C#基礎(string)

來源:互聯網
上載者:User

標籤:刪除字串   基本   格式   https   日期   for   例子   比較   form   

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
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

 







 

C#基礎(string)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.