您的位置:首页 > 其它

字符串的处理

2008-12-24 14:12 127 查看
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();

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: