Description: These string processing tips in peacetime programming will be generally encountered, summed up a lot, here only to provide some more fun for everyone's reference.
The basic method of implementation is the common method of string processing provided by C #, which is no longer described in one by one.
A. A string of branches based on punctuation marks
Input: ABC,DEFG,HIJKLMN,OPQ,RSTUV (by comma branch when testing, customizable line breaks)
Output: ABC
Defg
Hijklmn
Opq
Rstuv
Code
string oldstr = textBox1.Text.Trim();
string[] newstr = oldstr.Split(',');
for (int i = 0; i < newstr.Length; i++)
{
if (richTextBox1.Text == "")
richTextBox1.Text = newstr[i].ToString();
else
richTextBox1.Text += "\n" + newstr[i].ToString();
}
2. Reverse the string output
Input: ABCDEFG
Output: GFEDCBA
Code
string str1 = textBox1.Text.Trim();
char[] charstr = str1.ToCharArray();
Array.Reverse(charstr);
string str2 = new string(charstr);
textBox2.Text = str2;