[TIL] 107 IsNullOrWhiteSpace, trim

์—…๋ฐ์ดํŠธ:

์นดํ…Œ๊ณ ๋ฆฌ:

ํƒœ๊ทธ: , ,


IsNullOrWhiteSpace, trim



IsNullOrWhiteSpace


string input = Console.ReadLine();
string[] words = input.Trim().Split(' ');

if (words.Length == 1 && words[0]=="")
        {
            Console.WriteLine(0);
        }
        
if (string.IsNullOrWhiteSpace(input))
        {
            Console.WriteLine(0);
        }


  • string.IsNullOrWhiteSpace()
  • image







Trim()

์•ž ๋’ค ๊ณต๋ฐฑ์„ ๋ชจ๋‘ ์ œ๊ฑฐํ•œ ๋ฌธ์ž์—ด๋กœ ๋ฐ˜ํ™˜


string input = Console.ReadLine();
string[] words = input.Trim().Split(' ');

  • ์•ž ๋’ค ๊ณต๋ฐฑ์„ ๋ชจ๋‘ ์ œ๊ฑฐํ•œ ๋ฌธ์ž์—ด๋กœ ๋ฐ˜ํ™˜
  • TrimStart() ์•ž์ชฝ ๊ณต๋ฐฑ ์ œ๊ฑฐ.
  • TrimEnd() ๋’ค์ชฝ ๊ณต๋ฐฑ ์ œ๊ฑฐ.







์ˆซ์ž์˜ ๊ฐœ์ˆ˜

์ˆซ์ž, ์•„์Šคํ‚ค์ฝ”๋“œ, for ๋ฐฐ์—ด


string numstring = num.ToString(); //-> ex) 12305655476907

int[] count = new int[10];

foreach (char i in numstring) 
{
    count[i-'0']++;     //i =0~9  ์ˆซ์ž 0~9 => ์•„์Šคํ‚ค์ฝ”๋“œ 48~58 -'0' => 0~9 
}







์žก๋‹ด, ์ผ๊ธฐ?

์ด๋ ฅ์„œ ์ •๋ฆฌ, ์ž์†Œ์„œ ์ž‘์„ฑ, ๋ฉด์ ‘์ค€๋น„์ค‘, ์ฝ”ํ…Œ




๐Ÿ“”

๋Œ“๊ธ€๋‚จ๊ธฐ๊ธฐ