这样是写的第一个到最后一个空格之间的内容
比如:string str="this is an apple!";
System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex( "[ ]+" );
string replacedString = regex.Replace( str , " " );
比如:string str="this is an apple!";
System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex( "[ ]+" );
string replacedString = regex.Replace( str , " " );
string s=" dd d d ";
1:s=s.Trim();
2:s.Replace(" ","");
sb.Replace(" ","");
textBox1.Text=sb.ToString();当一个字符串有大量的增、改操作时
还是用StringBuilder来的好。
private void button1_Click(object sender, System.EventArgs e)
{
string delimStr = " "; //" "中为需要省略的字符
char [] delimiter = delimStr.ToCharArray();
string words = "this is an apple!"; //原如字符串
string [] split = null;
split = words.Split(delimiter, 5);
foreach (string s in split)
{
textBox1.AppendText(s);
}
}