码迷,mamicode.com
首页 > Windows程序 > 详细

c#常用类string

时间:2018-01-30 22:56:44      阅读:249      评论:0      收藏:0      [点我收藏+]

标签:字符串表   stat   nta   trim   bsp   col   bool   orm   public   

在 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());

 

c#常用类string

标签:字符串表   stat   nta   trim   bsp   col   bool   orm   public   

原文地址:https://www.cnblogs.com/guhun/p/8384584.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!