"hello world"字符串? ' h'字符? 空格也算字符
bool取值false和true镇匀,是0和1的區(qū)別敬锐;false可以代表0,但true有很多種纵竖,并非只有1彩匕。
c#中 布爾類型非0為真在旱,只有0為假
string? char
string str = "string";
字符串長(zhǎng)度
int a = str.Length;
Console.WriteLine ("{0}",a);? //a = 6
如何判斷兩個(gè)字符串恒等
string? str1? = "ni hao";
if (str1 == str){
?}
bool b = str1.Equals (str);
if (b) {
}
字符串的拼接
string str2 = str + str1;? //"1"+" "+"2" = "1 2";
string ZhangHao = "ni hao";
Console.WriteLine ("輸入帳號(hào)");
string ZhangHao1 = Console.ReadLine ( );
if (ZhangHao1 == ZhangHao) {
? ? ? ? ? ? ? ?Console.WriteLine ("帳號(hào)正確");
} else {
? ? ? ? ? ? ? ?Console.WriteLine ("錯(cuò)誤");
}
//登錄
string name = "admin",password = "123456";
Console.WriteLine ("輸入帳號(hào)");
string user_name = Console.ReadLine ( );
Console.WriteLine ("輸入密碼");
string user_password = Console.ReadLine ( );
// if (user_name == name && user_password == password) {
// ? ? ? ? ? ? ? ?Console.WriteLine ("真聰明");
// } else {
// ? ? ? ? ? ? ? ?Console.WriteLine ("大傻逼");
// }
if (user_name == name) {
? ? ? if (user_password == password) {
? ? ? ? ? ? ? ? ? Console.WriteLine ("小寶貝真聰明");
} else {
? ? ? ? ? ? ? ? ? Console.WriteLine ("密碼錯(cuò)了大傻逼");
}
} else {
? ? ? ? ? ? ? ? ? Console.WriteLine ("用戶名錯(cuò)了臭傻逼");
}
//判斷某頭字符串是否包含某個(gè)字符串
string str = "hellow";
str.Contains ("el");
bool b = str.Contains ("el");
Console.WriteLine ("{0}",b); ? ? ? ? ? ?//? true
//是否以某一個(gè)字符串結(jié)尾
str.EndsWith ("o");
//是否以某一個(gè)字符串開始
str.StartsWith ("h");
//右對(duì)齊
string newstar = str.PadLeft(15);
Console.WriteLine (newstar);
string str1 = "China";
string str2 = "English";
Console.WriteLine (str1.PadLeft(5)); ? ?//左縮進(jìn)5個(gè)字符
Console.WriteLine (str2.PadLeft(5));
//替換
string str = "hellow";
;string str3 = str.Replace ("ll","abcd");
Console.WriteLine (str3); ? ? ? ?//heabcdow
//轉(zhuǎn)換為大寫
string upper_Str = str.ToUpper();
Console.WriteLine (upper_Str); ? ?//HELLOW
//a轉(zhuǎn)A ? ASCLL碼控制
char n = (char)((int)'a' - 32);
Console.WriteLine ("{0}",n); ? ?//A
string str = "? ? hellow world ";
//從當(dāng)前的字符串中去移除頭部和尾部的空白字符
string str1 = str.Trim();
Console.WriteLine ("{0}",str1);
//截取字符串
string str2 = str1.Substring(4,4); ? ?//從第4個(gè)字符開始(不包含第4個(gè)) 截取長(zhǎng)度為4
Console.WriteLine("{0}",str2);
Console.WriteLine (str.Remove (1,3));? //刪除下標(biāo)為1 后面三個(gè)數(shù)(包括1)
Console.WriteLine(str.Substring(1,3));? //截取下標(biāo)為1 后面三個(gè)數(shù)(包括1);
//分割字符串
string str = "Stritritring ";
char[] chs = { 'i' }; ? ? ? ? ? //以i作為分割標(biāo)識(shí)?
string[] strs = str.Split(chs);
foreach (string s in strs) {
? ? ? ? ? Console.WriteLine (s); ? ? ? ?//Str tr tr ng
}