zoukankan      html  css  js  c++  java
  • C#常用类string

    在 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());
  • 相关阅读:
    STL:set/multiset用法详解
    STL:list用法详解
    STL:deque用法详解
    STL:vector容器用法详解
    Axure RP chrome插件显示已损坏或者无法安装的解决方法
    怎样知道自己机器的出口网关IP(即外部IP)
    [Selenium]怎样验证页面是否有无变化
    [Selenium]刷新页面 Refresh page
    [SoapUI]怎样获取隐藏元素的文本内容Get text of hidden element
    [SoapUI]怎样从应答报文中获取某个字段的值,然后用其改写某个变量
  • 原文地址:https://www.cnblogs.com/guhun/p/8384584.html
Copyright © 2011-2022 走看看