美文网首页
c#string字符串

c#string字符串

作者: 静水皎月 | 来源:发表于2017-08-09 00:05 被阅读0次

字符串: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);

相关文章

网友评论

      本文标题:c#string字符串

      本文链接:https://www.haomeiwen.com/subject/lrgtrxtx.html