[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(' ');

// [1,2,3] 
string result = arr.TrimStart('[').TrimEnd(']');
// 1,2,3

  • 앞 뒤 공백을 모두 제거한 문자열로 반환
  • 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 
}







잡담, 일기?

이력서 정리, 자소서 작성, 면접준비중, 코테




📔

댓글남기기