string类的常用方法

String类
1.方法public int IndexOf(
char value
)报告指定 Unicode 字符在此字符串中的第一个匹配项的从零开始的索引。
如果找到该字符,则为 value 的从零开始的索引位置;如果未找到,则为 -1。

2.public string Substring(
int startIndex,//此实例中子字符串的起始字符位置(从零开始)。
int length//子字符串中的字符数。
)从此实例检索子字符串。 子字符串从指定的字符位置开始且具有指定的长度。//主要用于裁剪字符串

3.public bool StartsWith(
string value
)确定此字符串实例的开头是否与指定的字符串匹配。
4.public bool EndsWith(
string value
)确定此字符串实例的结尾是否与指定的字符串匹配。

5.public string Trim(
params char[] trimChars//不能出现在字符串开头和结尾的字符
)从当前字符串的开头和结尾删除所出现的所有 trimChars 参数中的字符后剩余的字符串。

示例
string str = "bbebebebaaataffbtt";
str=str.Trim('b','t');//b和t均不能作为字符串的开头或结尾
Console.WriteLine(str);//输出结果为ebebebaaataff

 

6.

public string PadLeft(
int totalWidth,//结果字符串中的字符数,等于原始字符数加上任何其他填充字符。
char paddingChar//Unicode 填充字符。
)返回一个新字符串,该字符串通过在此实例中的字符左侧填充指定的 Unicode 字符来达到指定的总长度,从而使这些字符右对齐。

 

public string PadRight(
int totalWidth,
char paddingChar
)与PadLef类似

 

7.

public string Trim()
从当前 String 对象移除所有前导空白字符和尾部空白字符。

 

8.

public string ToUpper()
返回此字符串转换为大写形式的副本。

public string ToLower()
返回此字符串转换为小写形式的副本。

 

 

串联字符串数组的所有元素,其中在每个元素之间使用指定的分隔符。

public static string Join(
    string separator,
    params string[] value
)

 

 

 

 

posted @ 2014-05-27 16:32  ChuckLu  阅读(283)  评论(0编辑  收藏  举报