C# 关于string类的几个常用方法

  1. public string Trim()

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

  1. public static bool IsNullOrEmpty(string value)

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

  1. public string ToLower()

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

  1. public string ToUpper()

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

  1. public string Replace(char oldChar,char newChar)

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

  1. public static string Join(string separator,string[] value)

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

  1. public static string Join(string separator,string[] value,int startIndex,int count)

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

  1. public string[] Split(params char[] separator)

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

  1. public string[] Split(char[] separator,int count)

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

  1. public int LastIndexOf(char value)

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

  1. public int LastIndexOf(string value)

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

  1. public char[] ToCharArray()

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

  1. public char[] ToCharArray(int startIndex,int length)

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

  1. public bool StartsWith(string value)

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值