字符串:string關鍵字
1.通過string函數(shù)指定一個字符串
string names="Sun";
string name="";//字符串也可以設置成為空,用來存儲變量漠烧;
2.字符串之間的連接
string字符串之間的連接只要簡單的相加就行
string str1="hello";
string str2="world";
string str3=str1+" "+str2;
str3打印出來的為hello world蹬敲;
3.檢索字符串中的字符
//bool liu=people_name.startWith("劉");//startwith用來檢索是否以某個字符開頭
//bool liu=people_name.endWith("劉");//endWith用來檢索是否以某個字符串結尾
//bool liu=people_name.contains("劉");//contains用來檢索字符串中是否包含某個字符;
//string str=str.ToUpper();//轉換大小寫
//string str3="";string str1=str3.replace("hello");//替換字符
//Trim移除當前字符串中開頭和結尾的空格符岖研;//string str1="? ? ni hao? ";//string str2=str1.Trim();
//substring截取字符串丙挽;string? str2=str1.substring(開始截取的位置(int),截取的長度);
//string newStr=str.PadRight(15);//填充的右邊扁达,左對齊;
int people_number=int.parse(console.readline());//輸入人數(shù)惯豆;people_number在這里作了強制轉換
string name_liu="";? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //設置空string用來存儲姓劉的人的名字
for(int i=0;i<people.length;++i){
string people_names=console.readline();
bool liu=people_names.startwith("劉");
if(liu){
name_liu+=people_names;
}
}
console.writeline(name_liu);