using System;
using System.Collections.Generic;
using System.Text;
namespace Ch11Ex02
{
class Program
{
static void Main(string[] args)
{
string str1 = "this is a string";
string str2 = "this";
Console.WriteLine(string.Compare(str1, str2));//比较大小大于为1,小于为-1,等于为0
Console.WriteLine(string.Equals(str1, str2));//结果为true和fasce
Console.WriteLine(str1.IndexOf("is"));//查找
Console.WriteLine(str1.LastIndexOf("is"));
Console.WriteLine("{0}", str1.Insert(2, "abc"));//插入
Console.WriteLine("{0}",str1.Remove(2, 3));//删除
Console.WriteLine("{0}", str1.Replace("this", "that"));//替换
string []str=str1 .Split (' ');//分离
for (int i=0;i<str .Length ;i++)
{
Console .WriteLine (str [i ]);
}
char []charArray=str1.ToCharArray (); //复制
for (int i=0;i<charArray .Length ;i++)
{
Console .WriteLine (charArray [i ]);
}
Console.WriteLine("{0}", str1 .ToUpper ());//转大写
string str5 = " this is a book ";
string str3 = " this is a book";
string str4 = "this a book ";
Console.WriteLine(str5.Trim());//去空格
Console.WriteLine(str3.TrimStart());
Console.WriteLine(str4.TrimEnd());
Console.ReadKey();
}
}
}
浙公网安备 33010602011771号