C#程序检查给定字符串中是否存在子字符串
使用contains()C#中的方法检查子字符串是否在给定的字符串中。
让我们说字符串是-
United
在字符串中,您需要找到子字符串“Uni”。为此,请使用contains方法,并像下面的代码片段一样使用它-
res = str1.Contains(str2);
示例
您可以尝试运行以下代码以在字符串中找到子字符串。
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);
}
}输出结果
The substring Uni is in the string United
热门推荐
2 训练狗狗成为
3 训练狗狗几岁
4 反应训练狗狗
5 听力训练狗狗
7 狗狗尿训练
8 拳击训练狗狗
10 狗狗训练卧室
11 一个月狗狗怎么训练
12 几个月训练狗狗大小便
13 牧羊犬训练狗狗
14 狗狗训练做
15 狗狗训练它
16 可以训练狗狗
17 训练狗狗给球
18 训练狗狗的技巧