当前位置:首页 > Windows程序 > 正文

该值指示指定的 System.String 对象是否出现在此字符串中 bool isContains = contain

2024-03-31 Windows程序

在 C# 中,string 关键字来声明一个字符串变量,是 System.String 类的别号!

1.public string[] Split( params char[] separator ) 
   返回一个字符串数组,包罗当前的 string 东西中的子字符串,子字符串是使用指定的 Unicode 字符数组中的元素进行分隔断绝分手的

2.public static bool IsNullOrEmpty( string value ) 
   指示指定的字符串是否为 null 或者是否为一个空的字符串

3.public static string Format( string format, Object arg0 ) 
   把指定字符串中一个或多个格局项替换为指定东西的字符串暗示形式

4.public bool Contains( string value ) 
   返回一个暗示指定 string 东西是否呈此刻字符串中的值

5.public string Trim()
   移除当前 String 东西中的所有前导空白字符和后置空白字符

6.public string[] Split( char[] separator, int count ) 
   返回一个字符串数组,,包罗当前的 string 东西中的子字符串,子字符串是使用指定的 Unicode 字符数组中的元素进行分隔断绝分手的。int 参数指定要返回的子字符串的最大数目

string strSQL = "select * from {0}"; //将指定字符串中的一个或多个格局项替换为指定东西的字符串暗示形式 string strTempSQL = string.Format(strSQL, "Users"); Console.WriteLine(strTempSQL); string containsStr="playGames"; //返回一个值,该值指示指定的 System.String 东西是否呈此刻此字符串中 bool isContains = containsStr.Contains("Ga"); //指示指定的字符串是 null 还是 System.String.Empty 字符串 bool isNull = string.IsNullOrEmpty(containsStr); Console.WriteLine(isContains); Console.WriteLine(isNull); string splitStr = "str,yyx,jtx"; //返回的字符串数组包罗此实例中的子字符串(由指定 Unicode 字符数组的元素分隔断绝分手) string[] str = splitStr.Split(,); foreach(string strChar in str){ Console.WriteLine(strChar); } string trimStr = "str yyx jtx "; Console.WriteLine(trimStr.Trim());

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/35003.html

Jm-杰米博客Jamie
草根站长的技术交流乐园!IT不会不要紧快来好好学习吧!
  • 20786文章总数
  • 7494590访问次数
  • 建站天数
  • 友情链接