代碼如下:
//Trim:刪除開頭和結尾的空白,或從開頭或結尾移除指定的字符
txbVal.Text = sValue.Trim();
//TrimEnd:从字符串的结尾处移除在字符数组中指定的字符。
txbValue.Text = sValue.TrimEnd('!');
//TrimStart:从字符串的开头移除在字符数组中指定的字符。
txbValue1.Text = sValue.TrimStart('G');
//Remove:从字符串中的指定索引位置移除指定数量的字符。
txbVal2.Text = sValue.Remove(2);
//Replace:替換字符串中指定的字符
txbVal3.Text = sValue.Replace('!', '?');
//Insert:在指定位置插入字符
txbval4.Text = sValue.Insert(0,"Your ");
txbVal.Text = sValue.Trim();
//TrimEnd:从字符串的结尾处移除在字符数组中指定的字符。
txbValue.Text = sValue.TrimEnd('!');
//TrimStart:从字符串的开头移除在字符数组中指定的字符。
txbValue1.Text = sValue.TrimStart('G');
//Remove:从字符串中的指定索引位置移除指定数量的字符。
txbVal2.Text = sValue.Remove(2);
//Replace:替換字符串中指定的字符
txbVal3.Text = sValue.Replace('!', '?');
//Insert:在指定位置插入字符
txbval4.Text = sValue.Insert(0,"Your ");
結果如下圖:
注;MSDN資料: