c#string字符串

字符串:string关键字

1.通过string函数指定一个字符串

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());//输入人数;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);

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容