標籤:刪除字串 基本 格式 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)