private void Form1_Load(object sender, EventArgs e)
{
textBox1.Text = "123123";
}
private void button1_Click(object sender, EventArgs e)
{
string a = textBox1.Text;
string b = a.Substring(0, 2);
string[] str = a.Split('2');
textBox2.Text = b;
for (int i = 0; i < str.Count(); i++)
{
textBox3.Text += str[i] + " ";
}
}
其中substring的第一个参数为截取字符起始位置,第二个参数为截取的长度。(起始位置0开始)
附带分割“\r\n”的方法。以下方法转自:http://lemmychrist.blog.163.com/blog/static/987329632012422113034806/
1、直接分割
string[] method1 = text1.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
2、正则分割
Regex re = new Regex(@"\r\n");
string[] method2= re.Split(text2);
3、替换后分割,例如替换成@
text3=text3.Replace ("\r\n","@");
method3 = text3.Split('@');