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

using System;public class Demo {public static void Main() {string str1 = United, str2 = Uni;

编程学习网为您整理以下代码实例,主要实现: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);
   }
}

本文标题为:C#检查给定字符串中是否存在某子字符串

基础教程推荐