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#检查给定字符串中是否存在某子字符串

基础教程推荐