string Str = " 15年末 1063 ----";
string Arry[];
Arry[] =Str.Split(new char[]{' '},StringSplitOptions.RemoveEmptyEntries);
TextBox1.Text=Arry[2].ToString();////////////////////////////////以上为代码/////////////////////////////////////
Arry[] 为三维数组:"15年末"
"1063"
" ----" //为啥这个前面的空格去不掉呢?
/////////////////////////////////以上为调试结果/////////////////////////////////
Arry[] =Str.Split(new char[]{' ', '\t', '\r', '\n'}, StringSplitOptions.RemoveEmptyEntries);
第一个和第二个的空格都去掉了。不是空格会是什么啊?
如果说不是空格的话,那我用这个Trim()返回的东西就是正确的,去掉了前面的空白的。这是为什么?
Regex regex = new Regex(@"\s+");
string str = regex.Replace(Str, "");
用正则把,因为有些是制表符什么的
string Str = " 15年末 1063 ----";
string[] Arry;
Arry = Str.Split(new char[]{}, StringSplitOptions.RemoveEmptyEntries);
string Str = " 15年末 1063 ----";
string[] arr=Str.Split(new string[]{" "}, StringSplitOptions.RemoveEmptyEntries);.
string Str = " 15年末 1063 ----";
Str=Str.remove(13) //如果一个汉字算两个字符
Arry[] =Str.Split(new char[]{' '},StringSplitOptions.RemoveEmptyEntries);
TextBox1.Text=Arry[2].ToString();
//--------------------------//(2)
string Str = " 15年末 1063 ----";
Str=Str.remove(11) //如果一个汉字算一个字符
Arry[] =Str.Split(new char[]{' '},StringSplitOptions.RemoveEmptyEntries);
TextBox1.Text=Arry[2].ToString();
//-------------------------
上面两种方法,仅供参考