C# 字符串:
- 字符串 转 char类型的数组
- 字符串 批量合成
- 字符串大小写转换
- 字符串分割
- 字符串替换
- 字符串 是否包含
- 字符串 比较
- 字符串截取
- 字符串 是否 以什么开头、结尾、
- 字符串 第一个、最后一个、
- 字符串 去除空格
- 字符串 空与null 判定
- 字符串 合并,以什么相隔
string s1 = "张三";
string s2 = "张三";
Console.ReadKey();
string s = "abcdefg";
char[] cha = s.ToCharArray();
cha[0] = 'q';
Console.WriteLine(cha);
StringBuilder sb = new StringBuilder();
Stopwatch sw = new Stopwatch();
sw.Start();
for (int i = 0; i < 10000; i++)
{
sb.Append(i);
}
sw.Stop();
Console.WriteLine(sb.ToString());
Console.WriteLine(sw.Elapsed);
string str1 = "CAB";
string str2 = str1.ToLower();
Console.WriteLine(str2);
string str3 = str2.ToUpper();
Console.WriteLine(str3);
string st1 = "s1";
string st2 = "s2";
if (st1.Equals(st2, StringComparison.OrdinalIgnoreCase))
{
Console.WriteLine("字符串比较后是一样的");
}
else
{
Console.WriteLine("字符串比较后是不一样的");
}
string str_1 = "a b dfd _ + = ,,, fdf";
char[] chs1 = { ' ', '_', '=', ',' };
string[] str_2 = str_1.Split(chs1, StringSplitOptions.RemoveEmptyEntries);
Console.ReadKey();
string str_a1 = "国家关键人物 黑呵呵";
if (str_a1.Contains("国家"))
{
str_a1 = str_a1.Replace("国家", "**");
Console.WriteLine(str_a1);
}
string str = "今天天气很晴朗,处处好风光";
str = str.Substring(0, str.Length - 3);
Console.WriteLine(str);
string str = "今天天气很晴朗,处处好风光";
if (str.EndsWith("今天"))
{
Console.WriteLine("是");
}
else
{
Console.WriteLine("否");
}
string str = "今天天气很晴朗,处处好风光";
int index = str.IndexOf('天', 2);
Console.WriteLine(index);
string str = "今天天气很晴朗,处处好风光";
int index = str.LastIndexOf('天');
Console.WriteLine(index);
string path = @"da\d\a\d堆\a\d\asd\a叠\fa\堆叠.mp4";
int index = path.LastIndexOf('\\');
path = path.Substring(index + 1);
Console.WriteLine(path);
string str = " hhehehehehhehe 9 1 ";
str = str.Trim();
Console.WriteLine(str);
string str = "";
if (string.IsNullOrEmpty(str))
{
Console.WriteLine("是null 或者 空");
}
else
{
Console.WriteLine("不是null");
}
string[] names = { "王一", "王二", "王三", "网四" };
string strnew = string.Join("|", names);
Console.WriteLine(strnew);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)