‘408 0068D’中间有一个空格 ‘408 0068D‘和 ’差速锁指示灯开关’之间有3个空格
如何将字符串‘408 0068D 差速锁指示灯开关’ 分隔成
‘408 0068D’和‘差速锁指示灯开关’
谢谢
6 个解决方案
#1
string a = "‘408 0068D 差速锁指示灯开关’";
a = a.Replace(" ", "’和‘");
注:其中a = a.Replace("3个空格", "’和‘");
#2
try...
string test = "408 0068D 差速锁指示灯开关";
string[] result = test.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
foreach (string s in result)
{
richTextBox2.Text += s + "\n";
}
#3
Replce
空格按一下空格键
三个空格按三下
空格按一下空格键
三个空格按三下
#4
mark
#5
1楼完全理解错了!笑话!
不用Split,用Substring也可以:
string a = "408 0068D 差速锁指示灯开关";
string a1 = a.Substring(0, a.IndexOf(" ") - 1);
string a2 = a.Substring(a.IndexOf(" ")).Trim();
注:其中a.IndexOf(" ") 是两个空格或三个空格
不用Split,用Substring也可以:
string a = "408 0068D 差速锁指示灯开关";
string a1 = a.Substring(0, a.IndexOf(" ") - 1);
string a2 = a.Substring(a.IndexOf(" ")).Trim();
注:其中a.IndexOf(" ") 是两个空格或三个空格
#6
Regex r = new Regex(" ");
string[] s = r.Split("408 0068D 差速锁指示灯开关");
for(int i=0;i<s.Length;i++)
{
Response.Write(s[i]+"<br>");
}
string[] s = r.Split("408 0068D 差速锁指示灯开关");
for(int i=0;i<s.Length;i++)
{
Response.Write(s[i]+"<br>");
}
#1
string a = "‘408 0068D 差速锁指示灯开关’";
a = a.Replace(" ", "’和‘");
注:其中a = a.Replace("3个空格", "’和‘");
#2
try...
string test = "408 0068D 差速锁指示灯开关";
string[] result = test.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
foreach (string s in result)
{
richTextBox2.Text += s + "\n";
}
#3
Replce
空格按一下空格键
三个空格按三下
空格按一下空格键
三个空格按三下
#4
mark
#5
1楼完全理解错了!笑话!
不用Split,用Substring也可以:
string a = "408 0068D 差速锁指示灯开关";
string a1 = a.Substring(0, a.IndexOf(" ") - 1);
string a2 = a.Substring(a.IndexOf(" ")).Trim();
注:其中a.IndexOf(" ") 是两个空格或三个空格
不用Split,用Substring也可以:
string a = "408 0068D 差速锁指示灯开关";
string a1 = a.Substring(0, a.IndexOf(" ") - 1);
string a2 = a.Substring(a.IndexOf(" ")).Trim();
注:其中a.IndexOf(" ") 是两个空格或三个空格
#6
Regex r = new Regex(" ");
string[] s = r.Split("408 0068D 差速锁指示灯开关");
for(int i=0;i<s.Length;i++)
{
Response.Write(s[i]+"<br>");
}
string[] s = r.Split("408 0068D 差速锁指示灯开关");
for(int i=0;i<s.Length;i++)
{
Response.Write(s[i]+"<br>");
}