zoukankan      html  css  js  c++  java
  • IndexOf()、IndexOfAny()的用法 —— c#

    IndexOf()、IndexOfAny()的用法 —— c#

    2014年11月05日 14:41:41 紫冰寒寞 阅读数:9796

    1、String.IndexOf (value, [startIndex], [count])  

    例如str1.IndexOf('a',5,2)

    从str1字符串中的第5个字符开始,到第(5+2)=7位结束,查找在这个里面‘a'的位置

    若str1 = 'adskvlajeg',则str1.IndexOf('a',5,2)=6

    注:索引是从0开始的;

    indexof() :在字符串中从前向后定位字符和字符串;所有的返回值都是指在字符串的绝对位置,如为空则为- 1

    str1.IndexOf("字"); //查找“字”在str1中的索引值(位置)

    str1.IndexOf("字串");//查找“字串”的第一个字符在str1中的索引值(位置)

    lastindexof() :在字符串中从后向前定位字符和字符串;

    2、IndexOfAny、LastIndexOfAny

    返回数组中任何一个字符最早出现的下标位置,索引仍然是从‘0’开始

    例如:

           char[] bbv={'s','c','b'};

      string abc = "acsdfgdfgchacscdsad";  Response.Write(abc.IndexOfAny(bbv))=1  (abc字符串中最早出现的bbv中的字符是'c',c的索引是1)  Response.Write(abc.IndexOfAny(bbv, 5))=9  Response.Write(abc.IndexOfAny(bbv, 5, 4))=9  LastIndexOfAny 同上。

  • 相关阅读:
    脚本性能分析
    openwrt补丁
    定制openwrt的根文件
    openwrt路由器更换了Flash之后需要修改的源码
    openwrt驱动与应用程序的联系
    我的vi/vim配置文件
    Python中的字典分组函数(groupby,itertools)
    迭代器
    tuple
    list
  • 原文地址:https://www.cnblogs.com/grj001/p/12225218.html
Copyright © 2011-2022 走看看