
오늘 체크리스트 강의에서 다룬 String 클래스 메서드들 중 몰랐던 것만 정리해봤다.
지정된 문자열의 인스턴스를 연결해줌
string s1 = "hi ";
string s2 = "hello ";
string s3 = "bye";
string s = string.Concat(s1, s2, s3);
Console.WriteLine(s);

지정된 부분 문자열이 이 문자열 내에서 발생하는지 여부를 bool 값으로 줌
string s = "hi hello bye";
bool b = s.Contains("hello");
Console.WriteLine(b);

이 인스턴스에서 지정된 문자열이 처음 나타나는 인덱스를 알려줌
string s = "hi hello bye";
Console.WriteLine(s.IndexOf("hi"));
Console.WriteLine(s.IndexOf("hello"));
Console.WriteLine(s.IndexOf("bye"));

현재 문자열에서 문자의 모든 선행 및 후행 인스턴스를 제거
string s = " a! hi hello bye a? ";
s = s.Trim(); //공백 제거
s = s.Trim('a', '!', '?'); //해당 문자 제거
Console.WriteLine(s);

이 인스턴스에서 부분 문자열을 검색하고 그 위치에서 문자열의 끝까지가 됨
string s = "hi hello bye";
Console.WriteLine(s.Substring(3)); // 3 부터 끝까지
Console.WriteLine(s.Substring(3, 5)); // 3부터 5개 까지

내가 알던 것들도 있었는데 모르는게 더 많았다.
솔직히 많이 쓸지는 모르겠는데 알고 있으면 언제가 한번은 쓰지 않을까 싶어서
몰랐던 것들만 정리해봤다. 진짜 언젠가 한번쯤은 쓸 만 하다.