C_Sharp/Contains Case Intensive String 메소드


string str = "...";
if (str.Contains("..."))

이것(Contains)는 Case Intensive 찾기를 할 수 없다. 대신 IndexOf + StringComparison.CurrentCultureIgnoreCase를 사용하면 Case Intensive한 포함 찾기를 할 수 있다.

즉,

  1. public static bool ContainsCaseInsensitive(this string source, string value)
  2. {
  3.     int results = source.IndexOf(value, StringComparison.CurrentCultureIgnoreCase);
  4.     return results == -1 ? false : true;
  5. }

이 글에는 0 개의 댓글이 있습니다.