// split();除去字符串中不需要的字符,如空格等等返回字符串的数组
string s = "1, 2 3 5 ; = 8";
char[] chs = {'=' };
string []str=s.Split(chs,StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < str.Length; i++)
{
Console.Write(str[i]);
}
Console.ReadKey();
// 提示用户输入2008-02-9,你输出的日期为2008年1月2日
Console.WriteLine("请输入一个日期的格式");
string input = Console.ReadLine();
char[] chs = {'-' };
string []str = input.Split(chs,StringSplitOptions.RemoveEmptyEntries);
Console.WriteLine("{0}年{1}月{2}日",str[0],str[1],str[2]);
Console.ReadKey();
//length()方法,获得当前字符串中字符的个数
string[] s = { "123456"};
Console.WriteLine(s.Length);
ToUpper将字符串改成大写的 ToLower改成小写
Console.WriteLine("请输入科目");
string input = Console.ReadLine();
input=input.ToUpper();
Console.WriteLine("再输一次");
string input2 = Console.ReadLine();
input2 = input2.ToUpper();
if (input == input2)
{
Console.WriteLine("同一个");
}
else
{
Console.WriteLine("不一样");
}
Console.ReadKey();
// Equals(lesson,stringcomparison.ordinalignorecase)比较两个字符
Console.WriteLine("请输入科目");
string input = Console.ReadLine();
Console.WriteLine("再输一次");
string input2 = Console.ReadLine();
if (Equals(input, StringComparison.OrdinalIgnoreCase))
{
Console.WriteLine("相同");
}
else
{
Console.WriteLine("不同");
}
// substring 截取字符串,在截取的时候包含要截取的哪个位置
string s = "abcdefghj";
s=s.Substring(1, 5);
Console.WriteLine(s);
Console.ReadKey();
//indexof 字符串中第一次出现的字符 返回的是一个int类型 lastindexof最后一次出现的字符
string s = "1142589";
int a=s.IndexOf('9');
Console.WriteLine(a);
Console.ReadKey();
//contains判断字符串中是否有指定字符
string s = "12458684";
if (s.Contains("6"))
{
Console.WriteLine("有");
}
else { Console.WriteLine("没有");}
Console.ReadKey();
// startwith 判断以,,开始,endwith 以。。。结束
string s = "12345876";
if (s.StartsWith("4"))
{
Console.WriteLine("正确");
}
else
{
Console.WriteLine("false");
}
Console.ReadKey();
//replace将字符串某个字符替换成新的字符
string s = "国家关键人物老赵";
if (s.Contains("老赵"))
{
s= s.Replace("老赵", "**");
}
Console.WriteLine(s);
Console.ReadKey();
//trim 去掉空格 trimstart 去掉前面空格 trimend去掉后面空格
string s = " 125 125 ";
s=s.Trim();
Console.WriteLine(s);
Console.ReadKey();
// lastindexof 和 substring 连用要求截取"苍老师。waf"
string s = @"c:\s\s\s\s\s\sd\d\fg\h\苍老师。waf";
int index=s.LastIndexOf('\\');//从最后的“\”
s = s.Substring(index);//截取“\”后的内容
Console.WriteLine(s);
Console.ReadKey();
// string.isnullorempty判断一个字符串是否为空
string s = "123";
if (string.IsNullOrEmpty(s))
{
Console.WriteLine("是的");
}
else { Console.WriteLine("不是"); }
Console.ReadKey();
// string.join()将数组按照指定字符串连接
string[] s = { "张三","李四"};
string input=string.Join("\\", s);
Console.WriteLine(input);
Console.ReadKey();
string s = "1, 2 3 5 ; = 8";
char[] chs = {'=' };
string []str=s.Split(chs,StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < str.Length; i++)
{
Console.Write(str[i]);
}
Console.ReadKey();
// 提示用户输入2008-02-9,你输出的日期为2008年1月2日
Console.WriteLine("请输入一个日期的格式");
string input = Console.ReadLine();
char[] chs = {'-' };
string []str = input.Split(chs,StringSplitOptions.RemoveEmptyEntries);
Console.WriteLine("{0}年{1}月{2}日",str[0],str[1],str[2]);
Console.ReadKey();
//length()方法,获得当前字符串中字符的个数
string[] s = { "123456"};
Console.WriteLine(s.Length);
ToUpper将字符串改成大写的 ToLower改成小写
Console.WriteLine("请输入科目");
string input = Console.ReadLine();
input=input.ToUpper();
Console.WriteLine("再输一次");
string input2 = Console.ReadLine();
input2 = input2.ToUpper();
if (input == input2)
{
Console.WriteLine("同一个");
}
else
{
Console.WriteLine("不一样");
}
Console.ReadKey();
// Equals(lesson,stringcomparison.ordinalignorecase)比较两个字符
Console.WriteLine("请输入科目");
string input = Console.ReadLine();
Console.WriteLine("再输一次");
string input2 = Console.ReadLine();
if (Equals(input, StringComparison.OrdinalIgnoreCase))
{
Console.WriteLine("相同");
}
else
{
Console.WriteLine("不同");
}
// substring 截取字符串,在截取的时候包含要截取的哪个位置
string s = "abcdefghj";
s=s.Substring(1, 5);
Console.WriteLine(s);
Console.ReadKey();
//indexof 字符串中第一次出现的字符 返回的是一个int类型 lastindexof最后一次出现的字符
string s = "1142589";
int a=s.IndexOf('9');
Console.WriteLine(a);
Console.ReadKey();
//contains判断字符串中是否有指定字符
string s = "12458684";
if (s.Contains("6"))
{
Console.WriteLine("有");
}
else { Console.WriteLine("没有");}
Console.ReadKey();
// startwith 判断以,,开始,endwith 以。。。结束
string s = "12345876";
if (s.StartsWith("4"))
{
Console.WriteLine("正确");
}
else
{
Console.WriteLine("false");
}
Console.ReadKey();
//replace将字符串某个字符替换成新的字符
string s = "国家关键人物老赵";
if (s.Contains("老赵"))
{
s= s.Replace("老赵", "**");
}
Console.WriteLine(s);
Console.ReadKey();
//trim 去掉空格 trimstart 去掉前面空格 trimend去掉后面空格
string s = " 125 125 ";
s=s.Trim();
Console.WriteLine(s);
Console.ReadKey();
// lastindexof 和 substring 连用要求截取"苍老师。waf"
string s = @"c:\s\s\s\s\s\sd\d\fg\h\苍老师。waf";
int index=s.LastIndexOf('\\');//从最后的“\”
s = s.Substring(index);//截取“\”后的内容
Console.WriteLine(s);
Console.ReadKey();
// string.isnullorempty判断一个字符串是否为空
string s = "123";
if (string.IsNullOrEmpty(s))
{
Console.WriteLine("是的");
}
else { Console.WriteLine("不是"); }
Console.ReadKey();
// string.join()将数组按照指定字符串连接
string[] s = { "张三","李四"};
string input=string.Join("\\", s);
Console.WriteLine(input);
Console.ReadKey();