zoukankan      html  css  js  c++  java
  • 删除和剪切字符串

    如果从字符串中删除特定的字符。可以使用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)

  • 相关阅读:
    50个C/C++经典面试题
    多继承的构造顺序
    sizeof(struct)
    c++ 实现strcpy(),strlen()
    十天冲刺-01
    学习进度条(第八周)
    梦断代码阅读笔记01
    学习进度条(第七周)
    团队作业记账本开发NABCD
    学习进度条(第六周)
  • 原文地址:https://www.cnblogs.com/lichen396116416/p/1920421.html
Copyright © 2011-2022 走看看