位置:首頁 > 軟件操作教程 > 編程開發(fā) > C# > 問題詳情

字符串的操作方法

提問人:劉冬梅發(fā)布時間:2020-10-10

1.索引字符串中的單個字符

string str = “abcd”;

char c = str[0];

2.字符串連接

string s1 = “My age = “;

int myAge = 28;

string cat = s1 + myAge;

3.抽取和定位子串

string poem = “In Xanadu did Kubla Khan”;

string poemSeg = poem.Substring(10);

poemSeg = poem.Substring(0,9);

int index = poem.IndexOf(“I”);

index = poem.LastIndexOf(“n”);

4.比較字符串

bool isMatch;

string title = "Ancient Mariner";

isMatch = (title == "ANCIENT AMRINER");

isMatch = (title.ToUpper() == "ANCIENT MARINER");

isMatch = title.Equals("Ancient Mariner");


繼續(xù)查找其他問題的答案?

相關視頻回答
回復(0)
返回頂部