abcde -> edcba
string str = "abcde";
char[] chs = str.tochararray();
for (int i = 0; i < chs.length / 2; i++)
{
char temp = chs[i];
chs[i] = chs[chs.length - 1 - i];
chs[chs.length - 1 - i] = temp;
}
str = new string(chs);
console.writeline(str);
Console.ReadKey();
hello c sharp -> sharp c hello
string str = "hello c sharp";
string[] strNew = str.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < strNew.Length / 2; i++)
{
string temp = strNew[i];
strNew[i] = strNew[strNew.Length - 1 - i];
strNew[strNew.Length - 1 - i] = temp;
}
str = string.Join(" | ", strNew);
Console.WriteLine(str);
Console.ReadKey();
emal提取:abc@163.com -> abc 163.com
string email = "abc@163.com";
int index = email.IndexOf('@');
string userName = email.Substring(0, index);
string yuming = email.Substring(index + 1);
Console.WriteLine(userName);
Console.WriteLine(yuming);
Console.ReadKey();
找 e 的位置
String str = "abcdefgegegegegeg";
int index = str.IndexOf('e');
Console.WriteLine("第1次出现e的位置{0}", index);
int count = 1;
while (index != -1)
{
count++;
index = str.IndexOf('e', index + 1);
if (index == -1)
{
break;
}
Console.WriteLine("第{0}次出现e的位置{1}", count, index);
}
Console.ReadKey();
老牛很邪恶 -> 老牛很**
string str = "老牛很邪恶";
if (str.Contains("邪恶"))
{
str = str.Replace("邪恶", "**");
}
Console.WriteLine(str);
Console.ReadKey();
{ "诸葛亮", "鸟叔", "卡卡西" } 变成 诸葛亮|鸟叔|卡卡西。2、把 “|” 去掉。
string[] names = { "诸葛亮", "鸟叔", "卡卡西" };
string str = string.Join("|", names);
string[] strNew = str.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
str = string.Join("", strNew);
Console.WriteLine(str);
Console.ReadKey();