删除和剪切字符串

如果从字符串中删除特定的字符。可以使用system.String类中的Remove方法,另外system.string 还提供了很多的从字符串中的剪切方法。

public string Remove(int  startIndex)//startIndex指定索引的位置

public string Remove(int startindex ,int count)//count 指定要删除的长度

下面举例说明

  string strRemove = "演示Remove功能";
            Console.WriteLine(strRemove.Remove(2));//删除索引以后的所有
            Console.WriteLine(strRemove.Remove(2,6));//删除指定的长度

剪切字符串

在system.string 中提供了三种方法来剪切字符串

如下:

//从字符串的开头和结尾处,移除空白或者是字符串数组中指定的字符。如果trimchar指定为空,则移除空白字符

public string Trim() public string Trim(Params shar[] trimChar)

从字符串的结尾处移除在字符串数组中的指定的字符

public string TrimEnd(params char[] trimChars)

从字符串的来头处移除在字符串数组中的指定的字符

public string TrimStart(params char[] trimChars)

原文地址:https://www.cnblogs.com/lichen396116416/p/1920421.html