编程语言
首页 > 编程语言> > C# 通关手册(持续更新......)

C# 通关手册(持续更新......)

作者:互联网

转载请注明来源 https://www.cnblogs.com/brucejiao/p/16188865.html 谢谢!
转载请注明来源 https://www.cnblogs.com/brucejiao/p/16188865.html 谢谢!
转载请注明来源 https://www.cnblogs.com/brucejiao/p/16188865.html 谢谢!


String

常用静态方法

string.Compare(string str1,string str2,bool ignoreCase)

按照字典顺序比较字符串

当str1 > str2时,返回1
当str1 = str2时,返回0
当str1 < str2时,返回-1

ignoreCase:true 忽略大小写

string.Concat(string str1,string str2)

 string str=string.Concat("c","#"); //str="c#";

String.Format(string str)

string str=String.Format("今年是{0}年","2022");//str="今年是2022年";

string.IsNullOrEmpty(string str1)

string str2="";
bool b2=string.IsNullOrEmpty(str2);//b2=true;

string str3=null;
bool b3=string.IsNullOrEmpty(str3);//b3=true;

string.Join(string str,string[] strArr)

string strs=string.Join(",",string[]{"w","e","r","t"});//strs="w,e,r,t";

split去重

string update_invoice = FINVO System.CollectionICENUMBER + "," + invoiceNumber; // 追加发票号
string[] oldInvoiceList = update_invoice.Split(new Char[] { ',' });
string update_invoice_str = string.Join(",", oldInvoiceList.Distinct().ToArray());

Contains

string str="我爱编程";
bool b=str.Contains("程");//b=true;

StartsWith/EndsWith

string str="我好喜欢你";

bool b1=str.StartsWith("好");//b1=false;

bool b2-str.EndsWith("你");//b2=true;

Equals

string str1="asd";
string str2="ert";

bool  b = str1.Equals(str2);  //b=false;
bool <strName>.Equals(string str, StringComparison.OrdinalIgnoreCase)   //表示不区分大小写

IndexOf/LastIndexOf

string str ="今天的雨很大,天很冷";

int i=str.IndexOf("很"); //i=4;
int i=str.LastIndexOf("很");//j=8;
int m=str.IndexOf("小");//m=-1;

Replace

string str="好困呀";
string s=str.Replace("困","精神");//s="好精神呀";

Insert

string str="夜深了";
string s=str.Insert(1,"已经");// s="夜已经深了"

Remove