C#字符串练习
来源:互联网 发布:设计模式 python 书 编辑:程序博客网 时间:2024/06/05 15:32
将字符串字符反输出
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();
阅读全文
0 0
- C#字符串练习
- C# 字符串练习,字符串反转,字符串分割
- C#学习:字符串综合练习
- C#学习笔记007-字符串练习
- C#练习——字符串字符个数,简单数学题
- C# 实例练习——字符串处理(第一天)
- C# 实例练习——字符串处理(第三天)
- 字符串练习
- 字符串 练习
- 字符串练习
- 字符串练习
- 字符串练习
- 字符串练习
- 字符串练习
- 字符串练习
- 字符串练习
- 字符串练习
- 字符串练习
- linux开发环境搭建
- SpringBoot中配置简介
- RSA、DSA和ECDSA三者的签名
- 结构体
- google地图静态下载和js调用
- C#字符串练习
- crm代码评审学习
- java怎么把图片以base64字节存入数据库,并将其显示到jsp页面上
- AndroidStudio3.0特性
- 基本排序算法
- c++引用与指针的区别(着重理解)
- Java高级篇-0-为什么要掌握Java高级篇知识
- Android studio混淆 打包 日志错误日志跟踪
- 使用Python发送和读取Lotus Notes邮件