将字符串字符反输出
string s = "1258955";
char[] chs = s.ToCharArray();//将字符串数组转化为char数组
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;
}
s = new string(chs);
Console.WriteLine(s);
Console.ReadKey();
将“hello you world”反向输出“world you hello”
string s = "hello you world";
char[] chs = {' ','=' };
string []str=s.Split(chs);//除去chs数组中不需要的字符
string ss = "";
for (int i = str.Length - 1; i >= 0; i--)
{
ss+=str[i]+" ";
}
Console.WriteLine(ss);
Console.ReadKey();
找用户名和域名
string s = "1508602377@qq.com";
int index = s.IndexOf('@');
string usename = s.Substring(0, index);
string yuming = s.Substring(index+1);
Console.WriteLine("用户名{0},域名{1}",usename,yuming);
Console.ReadKey();
找出字符串中所有e所在的位置
string s = "aghdeyeeeeeyeueyeieiueiueehjehjeejj";
int index = s.IndexOf('e');
Console.WriteLine("第一次出现的位置为{0}",index);
while (index != -1)
{
index=s.IndexOf('e', index+1);
Console.WriteLine(index);
}
Console.ReadKey();
让用户输入一句话判断有没有邪恶两个字,有的话用**替换
string s = "老赵是个邪恶的人" ;
if (s.Contains("邪恶"))
{
s = s.Replace("邪恶", "**");
}
Console.WriteLine(s);
Console.ReadKey();
把{“诸葛亮”,“鸟叔”,“卡哇伊”},变成诸葛亮|鸟叔|卡哇伊
string[] s = { "诸葛亮", "鸟叔", "卡哇伊" };
string ss = string.Join("|", s);
Console.WriteLine(ss);
Console.ReadKey();
string s = "1258955";
char[] chs = s.ToCharArray();//将字符串数组转化为char数组
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;
}
s = new string(chs);
Console.WriteLine(s);
Console.ReadKey();
将“hello you world”反向输出“world you hello”
string s = "hello you world";
char[] chs = {' ','=' };
string []str=s.Split(chs);//除去chs数组中不需要的字符
string ss = "";
for (int i = str.Length - 1; i >= 0; i--)
{
ss+=str[i]+" ";
}
Console.WriteLine(ss);
Console.ReadKey();
找用户名和域名
string s = "1508602377@qq.com";
int index = s.IndexOf('@');
string usename = s.Substring(0, index);
string yuming = s.Substring(index+1);
Console.WriteLine("用户名{0},域名{1}",usename,yuming);
Console.ReadKey();
找出字符串中所有e所在的位置
string s = "aghdeyeeeeeyeueyeieiueiueehjehjeejj";
int index = s.IndexOf('e');
Console.WriteLine("第一次出现的位置为{0}",index);
while (index != -1)
{
index=s.IndexOf('e', index+1);
Console.WriteLine(index);
}
Console.ReadKey();
让用户输入一句话判断有没有邪恶两个字,有的话用**替换
string s = "老赵是个邪恶的人" ;
if (s.Contains("邪恶"))
{
s = s.Replace("邪恶", "**");
}
Console.WriteLine(s);
Console.ReadKey();
把{“诸葛亮”,“鸟叔”,“卡哇伊”},变成诸葛亮|鸟叔|卡哇伊
string[] s = { "诸葛亮", "鸟叔", "卡哇伊" };
string ss = string.Join("|", s);
Console.WriteLine(ss);
Console.ReadKey();