C#中System.String类

来源:互联网 发布:报考东华大学网络教育 编辑:程序博客网 时间:2024/06/05 21:09

C#中System.String类

++System.String

++++这个类可以完成很多的常见的任务,如替换字符串、删除空白字符串和把字母变成大写形式等。

++++++Compare比较字符串的内容,判断字符串某些字符是否相等。

++++++Contains返回一个值,该值只是指定的子串是否出现在字符串中。

++++++Remove返回指定数量字符在当前这个实例起始点在已删除的指定的位置的新字符串。

++++++Concat把多个字符串实例合并为一个实例。

++++++CopyTo把从选定的下标开始的特定数量的字符复制到数组的一个全新实例中。

++++++Format格式化包含各种值的字符串和如何格式化每个值的说明符。

++++++IndexOf定位字符串中第一次出现某个给定子字符串或字符的位置。

++++++IndexOfAny定位字符串中第一次出现某个字符或一组字符的位置。

++++++Insert把一个字符串实例插入到另一个字符串实例的指定索引处。

++++++Join合并字符串数组,创建一个新的字符串。

++++++LastIndexOfIndexOf一样,但定位最后一次出现的位置。

++++++LastIndexOfAnyIndexOfAny一样,但定位最后一次出现的位置。

++++++PadLeft在字符串的左侧,通过添加指定的重复字符填充字符串。

++++++PadRight在字符串的右侧,通过添加指定的重复字符填充字符串。

++++++Replace用另一个字符或子字符串替换字符串中给定的字符或子字符串。

++++++Split在出现给定字符的地方,把字符串拆分为一个子字符串数组。

++++++SubString在字符串中检索给定位置的子字符串。

++++++ToLower把字符串转换为小写形式。

++++++ToUpper把字符串转换为大写形式。

++++++Trim删除首尾的空白。


++++String类的方法:

--1public static intCompare(string strA, string strB)

    比较两个指定的string对象,并返回一个表示它们在排列顺序中相对位置的整数。该方法区分大小写。

--2public static int Compare(string strA, string strB, bool ignoreCase)

    比较两个指定的string对象,并返回一个表示它们在排列顺序中相对位置的整数。 但是,如果布尔参数为真时,该方法不区分大小写。

--3public static string Concat(string str0, string str1)

    连接两个string对象。

--4public static string Concat(stirng str0, string str1, string str2)

    连接三个string对象。

--5public static string Concat(string str0, string str1, string str2, string str3)

    连接四个string对象。

--6public boolContains(string value)

    返回一个表示指定string对象是否出现的字符串中的值。

--7public static stringCopy(string str)

    创建一个与指定字符串具有相同值的新的String对象。

--8public voidCopyTo(int sourceIndex, char[] destination, int destinationIndex, int count)

    string对象的指定位置开始复制指定数量的字符到Unicode字符数组中的指定位置。

--9public boolEndsWith(string value)

    判断string对象的结尾是否匹配指定的字符串。

--10public boolEquals(string value)

    判断当前的string对象是否与指定的string对象具有相同的值。

--11public static boolEquals(string a, string b)

    判断两个指定的string对象是否具有相同的值。

--12public static stringFormat(string format, Object arg0)

    把指定字符串中一个或多个格式项替换为指定对象的字符串表示形式。

--13public int IndexOf(char value)

    返回指定Unicode字符在当前字符串中第一次出现的索引,索引从0开始。

--14public int IndexOf(string value)

    返回指定字符串在该实例中第一次出现的索引,索引从0开始。

--15public int IndexOf(char value, int startIndex)

    返回指定Unicode字符从该字符串中指定字符位置开始搜索第一次出现的索引,索引从0开始。

--16public intIndexOf(string value, int startIndex)

    返回指定字符串从该实例中指定字符位置开始搜索第一次出现的索引,索引从0开始。

--17public intIndexOfAny(char[] anyOf)

    返回某一个指定的Unicode字符数组中任意字符在该实例中第一次出现的索引,索引从0开始。

--18public int IndexOfAny(char[] anyOf, int startIndex)

    返回某一个指定的Unicode字符数组中任意字符从该实例中指定字符位置开始搜索第一次出现的索引,索引从0开始。

--19public stringInsert(int startIndex, string value)

    返回一个新的字符串,其中,指定的字符串被插入在当前string对象的指定索引位置。

--20public static bool IsNullOrEmpty(string value)

    指示指定的字符串是否为null或者是否为一个空的字符串。

--21public static stringJoin(string separator, string[] value)

    连接一个字符串数组中的所有元素,使用指定的分隔符分隔每个元素。

--22public static string Join(string separator, string[] value, int startIndex, int count)

    连接一个字符串数组中指定位置开始的指定元素,使用指定的分隔符分隔每个元素。

--23public intLastIndexOf(char value)

    返回指定Unicode字符在当前string对象中最后一次出现的索引位置,索引从0开始。

--24public int LastIndexOf(string value)

    返回指定字符串在当前string对象中最后一次出现的索引位置,索引从0开始。

--25public string Remove(int startIndex)

    移除当前实例中的所有字符,从指定位置开始,一直到最后一个位置为止,并返回字符串。

--26public stringRemove(int startIndex, int count)

    从当前字符串的指定位置开始移除指定数量的字符,并返回字符串。

--27public string Replace(char oldChar, char newChar)

    把当前string对象中,所有指定的Unicode字符替换为另一个指定的Unicode字符,并返回新的字符串。

--28public string Replace(string oldValue, string newValue)

    把当前string对象中,所有指定的字符串替换为另一个指定的字符串,并返回新的字符串。

--29public string[] Split(params char[] separator)

    返回一个字符串数组,包含当前的string对象中的子字符串,子字符串是使用指定的Unicode字符数组中的元素进行分割的。

--30public string[]Split(char[] separator, int count)

    返回一个字符串数组,包含当前的string对象中的子字符串,子字符串是使用指定的Unicode字符串数组中的元素进行分割的。int参数指定要返回的子字符串的最大数目。

--31public boolStartsWith(string value)

    判断字符串实例的开头是否匹配指定的字符串。

--32public char[] ToCharArray()

    返回一个带有当前string对象中所有字符的Unicode字符数组。

--33public char[]ToCharArray(int startIndex, int length)

    返回一个带有当前string对象中所有字符的Unicode字符数组,从指定的索引开始,直到指定的长度为止。

--34public string ToLower()

    把字符串转换为小写并返回。

--35public stringToUpper()

    把字符串转换为大写并返回。

--36public stringTrim()

    移除当前String对象中的所有前导空白字符和后置空白字符。


拓展:StringBuilder类

++StringBuilder

++++StringBuilder也有很多常用方法

++++++Append给当前字符串追加一个字符串。

++++++AppendFormat追加特定格式的字符串。

++++++Insert在当前字符串中插入一个子字符串。

++++++Remove从当前字符串中删除字符。

++++++Replace在当前字符串中,用某个字符(串)替换另一个字符(串)。

++++++ToString返回强制转换为System.String对象的字符串。



--_--VRunSoft:lovezuanzuan--_--

原创粉丝点击