C# 属性

C# 抽象

C# 字符串

C# 泛型

C# 杂项

C# 新特性

C# Contains() 包含字符串

C# Contains() 方法用于返回一个值,该值指示指定的子字符串是否出现在此字符串中。如果在此字符串中找到指定的子字符串,则返回 true,否则返回 false。

签名

句法 (Syntax)

public bool Contains(String str)

参数

str:它是一个字符串对象,用于检查调用字符串中的出现。

返回

它返回布尔值 true 或 false。


C# String Contains() 方法示例

例子 (Example)

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


  • 使用社交账号登录,本站支持
全部评论(0)