using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace _2152
{
class Program
{
static void Main(string[] args)
{
string str1 = "aBc";
char[] chrs = str1.ToCharArray();//把string转化为char[]
foreach(char chr in chrs)
{
Console.WriteLine(chr);
}
str1 = str1.ToLower();//返回string类型,把字符串变为小写
Console.WriteLine(str1);
str1 = str1.ToUpper();//返回string类型,把字符串变为大写
Console.WriteLine(str1);
bool b = str1.Equals("ABC", StringComparison.OrdinalIgnoreCase);//忽略大小写比较
Console.WriteLine(b);
string str2 = " what a good day! ";
str2 = str2.Trim();//去掉字符串两边的红白,中间的空白不去除
Console.WriteLine(str2);
string str3 = "aa,b|c,ff.h";
string[] str4 = str3.Split(',', '|', '.');
foreach(string item1 in str4)
{
Console.WriteLine(item1);
}
string str5 = ",,c,,b,c,,,,c";
string[] str6 = str5.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
foreach (string item2 in str6)
{
Console.WriteLine(item2);
}
string str7 = "我是狗我是猫我是王八蛋";
string[] str8 = str7.Split(new string[] { "我是" }, StringSplitOptions.RemoveEmptyEntries);
foreach(string item3 in str8)
{
Console.WriteLine(item3);
}
str7 = str7.Replace("我是", "你是");//原型string Replace(string oldString, string newString);//用新串替换旧窜
Console.WriteLine(str7);
str7 = str7.Substring(6);//得到从某个位置开始至字符串末尾的子串
Console.WriteLine(str7);
str7 = str7.Substring(0, 2);//得到从某个位置开始并且长度为length的子串
Console.WriteLine(str7);
string str9 = "what a good day! Let's party,goodbye";
bool b1 = str9.Contains("what");//判断串中是否含有某个串
Console.WriteLine(b1);
bool b2 = str9.StartsWith("where");//判断串是否是以某个串开始
Console.WriteLine(b2);
bool b3 = str9.EndsWith("bye");//判断串是否是以某个串结束
Console.WriteLine(b3);
int ipos = str9.IndexOf("day");//某个串第一次出现的位置
Console.WriteLine(ipos);
Console.ReadKey();
}
}
}