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

       

  • 相关阅读:
    自动化测试成功11333
    自动化测试成功11222
    自动化测试成功1111
    自动化测试成功112
    自动化测试成功18
    自动化测试成功1
    自动化测试成功
    富文本测试
    关于VMware虚拟机磁盘收缩的几种方法
    8个让你更有效率的简单方法
  • 原文地址:https://www.cnblogs.com/linsu/p/2268432.html
Copyright © 2011-2022 走看看