C# Contains() 方法用于返回一个值,该值指示指定的子字符串是否出现在此字符串中。如果在此字符串中找到指定的子字符串,则返回 true,否则返回 false。
public bool Contains(String str)
str:它是一个字符串对象,用于检查调用字符串中的出现。
它返回布尔值 true 或 false。
using System; public class StringExample { public static void Main(string[] args) { string s1 = "Hello "; string s2 = "He"; string s3 = "Hi"; Console.WriteLine(s1.Contains(s2)); Console.WriteLine(s1.Contains(s3)); } }
输出:
True False