当前位置:首页 > C#教程 > C#进阶

C#检查给定字符串中是否存在某子字符串

using System;

public class Demo {
   public static void Main() {
      string str1 = "United", str2 = "Uni";
      bool res;

      res = str1.Contains(str2);
      if (res)
         Console.Write("The substring " + str2 + " is in the string " + str1);
      else
         Console.Write("The substring " + str2 + " is not in the string " + str1);
   }
}

【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!