zoukankan      html  css  js  c++  java
  • C#基础(string)

    https://msdn.microsoft.com/zh-cn/library/84787k22(v=vs.110).aspx

    1、Compare
    基本方法
    public static int Compare(
    	string strA,
    	string strB
    )
    调用
    String.Compare(s1, s2)
    重载1

    public static int Compare(
    	string strA,
    	string strB,
    	bool ignoreCase  //忽略大小写
    )
    重载2
    public static int Compare(
    	string strA,
    	string strB,
    	bool ignoreCase,
    	CultureInfo culture  //一个对象,提供区域性特定的比较信息
    )

    2、CompareTo

    https://www.cnblogs.com/jhxk/articles/1733811.html

    String.CompareTo 语法

    public int CompareTo(
        string strB
    )
     CompareTo 很少用,不要用 CompareTo 来比较两个字符串是否相等,要用 Equals。
    3、Equals
    https://blog.csdn.net/ecidevilin/article/details/52446664
    两种重载
    public bool Equals(string value);
    public static bool Equals(string a,string b);

    4、格式化字符串
    public static string Format(string format,object obj);
    调用例子
    string.Format("{0},{1}",strA,strB)
    string.Format("{0}:D",strA)//格式化日期

    5、截取字符串
    public string substring(int startIndex,int length);

    6、分割字符串
    public string[] Split(param char[] separator);
    7、插入和填充字符串
    public string insert(int startIndex,string value);
    8、填充字符串

    方法1:

    使用string.PadRight()

    方法2:

    自定义一个字符串补齐的静态方法:

        public static string PadRight(string src, char c, Int32 totalLength)
            {
                if (totalLength < src.Length)
                    return src;
                return src + new String(c, totalLength - src.Length);
            }

     https://www.cnblogs.com/IamJiangXiaoKun/p/5737822.html

    9、删除字符串

    str1.Remove(3); //字符串str1从第三位开始删除

    str1.Remove(3,10);  //字符串str1从第三位开始删除,删除位数10位

    10、复制字符串

    Copy()

    strB=string.Copy(strA)   //将字符strA复制给strB

    11、替换字符串

    string strB=strA.Replace("one","One"); //将字符串strA中的one替换为One







     
  • 相关阅读:
    freemarker.core.ParseException:Unexpected end of file reached
    freemarker.template.TemplateException:Error executing macro:mainSelect
    Perl--子程序传参
    MFC管理员权限(UAC下的程序权限提升)
    高级编程
    vmstat 查看堵塞的队列
    linux crontab 文件位置和日志位置
    linux 定时执行shell脚本 crontab
    Redis 命令参考 » Server(服务器)
    AiX--Ipcs 资源
  • 原文地址:https://www.cnblogs.com/CelonY/p/9215599.html
Copyright © 2011-2022 走看看