zoukankan      html  css  js  c++  java
  • C#中处理字符串对象的函数

    1.Substring

      Substring(startIndex);

      startIndex
    Type: System.Int32
    The zero-based starting character position of a substring in this instance. 

       string str="ABCDEFG";

       str.Substring(2); // returns "CDEFG"

       str.Substring(7);//returns an empty string

       str.Substring(8);//Causes an ArgumentOutOfRangeException 

      

      Substring(startIndex,length);

         startIndex
    Type: System.Int32
    The zero-based starting character position of a substring in this instance.
         length
    Type: System.Int32
    The number of characters in the substring. 
    str.Substring(2,1); // returns "C"

            str.Substring(7,0);//returns an empty string

            str.Substring(8,1);//This throws ArgumentOutOfRangeException  

    2.LastIndexOf

      value

    Type: System.String
    The string to seek.  

    string str="<b>This is bold text</b>";
    int endTagStartPosition = item.LastIndexOf("</"); // Remove the identified section, if it is valid.
    if (endTagStartPosition >= 0 ) item = item.Substring(0, endTagStartPosition);

    int openTagEndPosition = item.IndexOf(">"); // Remove the identified section, if it is valid.
    if (openTagEndPosition >= 0) item = item.Substring(openTagEndPosition + 1);
    Console.WriteLine("str: " + item); //This is bold text

       

  • 相关阅读:
    springmvc 处理静态资源
    springmvc jsp 获取 上下文
    springmvc 如何设置首页
    servlet-mapping url-pattern / 和 /*区别
    nginx支持php
    openresty 变量
    git tag用法
    python 导入模块,__init__.py 的作用
    python 转码问题
    python装饰器
  • 原文地址:https://www.cnblogs.com/linsu/p/2268432.html
Copyright © 2011-2022 走看看