using System;
class Program
{
static void Main()
{
string sentence = "Hello, welcome to the world of C#!";
// 使用 Contains 方法检查字符串中是否包含指定的子字符串
bool containsCSharp = sentence.Contains("C#");
if (containsCSharp)
{
Console.WriteLine("The sentence contains 'C#'.");
}
else
{
Console.WriteLine("The sentence does not contain 'C#'.");
}
}
}
Contains
是 C# 中 string
类的一个方法,用于检查一个字符串是否包含指定的子字符串。sentence
,然后使用 Contains
方法来检查该字符串是否包含子字符串 "C#"
。"The sentence contains 'C#'."
;否则,输出 "The sentence does not contain 'C#'."
。上一篇:c# hashtable
下一篇:c# tcp
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站