C#string 类
---恢复内容开始---
string类
系统内置的处理字符串类型的函数方法类。
.length 获取字符长度
.trim 去掉前后空格
.trim start/end 去掉前面/后面的空格
.to upper/.to lower 小写字母转大写/大写字母转小写
indexof/last indexof 索引第一次/最后一次出现的字符串的索引号
.startswith/.ends with 是否以...开头/结尾
.contains 是否包含...
.replace 替换
.ceiling/.floor 去上线/下线
例题:
Console.Write("请输入邮箱账号:");
string yx = Console.ReadLine();
if (yx.Contains("@"))
{
int a = yx.IndexOf("@");
int b = yx.LastIndexOf("@");
if (a == b) //保证只有一个@
{
if (!yx.StartsWith("@")) //保证不以@开头
{
string yx1 = yx.Substring(a);
if (yx.Contains(".")) //保证@后面至少有一个.
{
if (!yx.Contains(".@") && !yx.Contains("@."))//确保账号里没有@.和.@
{
if (!yx.EndsWith("."))//保证不以.结尾
{
Console.WriteLine("您输入的邮箱格式正确!");
}
else
{
Console.WriteLine("您输入的格式有误!");
}
}
else
{
Console.WriteLine("您输入的格式有误!");
}
}
else
{
Console.WriteLine("您输入的格式有误!");
}
}
else
{
Console.WriteLine("您输入的格式有误!");
}
}
else
{
Console.WriteLine("您输入的格式有误!");
}
}
else
{
Console.WriteLine("您输入的格式有误!");
}
}
---恢复内容结束---