IndexOf、IndexOfAny 、Remove

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Test2
{
    class Program
    {
        static void Main(string[] args)
        {
            // //1、indexof() :在字符串中从前向后查找某个字符,如找到就输出位置,如没找到则为 - 1

            //string test = "asdfjsdfjgkfasdsfsgfhgjgfjgdddd";

            //int index1=test.IndexOf('d');   //从前向后  从第0位开始查找
            //Console.WriteLine(index1); //2    

            //int index2 = test.IndexOf('d',3); //从前向后  从第3位开始查找
            //Console.WriteLine(index2); //2

            //int index3 = test.IndexOf('d',5,2); //从前向后  从第5 位开始查,向后查两位,即从第5位到第7位;  
            //Console.WriteLine(index3); //6

            ////LastIndexOf() 在字符串中从后向前定位字符和字符串;  用法和 indexof() 完全相同。  


            ////2、IndexOfAny || lastindexofany

            ////他们接受字符数组做为变元,其他方法同上,返回数组中任何一个字符最早出现的下标位置

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

            //string str2 = "acsdfgdfgchacscdsad";

            //Console.WriteLine(str2.IndexOfAny(s));
            //Console.WriteLine(str2.IndexOfAny(s,9));
            //Console.WriteLine(str2.IndexOfAny(s,5,3)); //没找到就显示-1


            ////LastIndexOfAny() 在字符串中从后向前定位字符和字符串; 用法同上。
            //跟多详情百度:LastIndexOf MSDN

            //3、Remove 有两个重载
            //Remove(Int32) 删除此字符串中从指定位置到最后位置的所有字符。  
            //Remove(Int32, Int32) 从此实例中的指定位置开始删除指定数目的字符。

            //string test = "asdfjsdfjgkfasdsfsgfhgjgfjgdddd";

            //string index2 = test.Remove(2);
            //Console.WriteLine(index2); //as

            //string index3 = test.Remove(2, 2);
            //Console.WriteLine(index3); //asjsdfjgkfasdsfsgfhgjgfjgdddd

            ////中文字符呢?
            //string test = "圣g诞节dsg来了,收到jgdddd";

            //string index2 = test.Remove(2);
            //Console.WriteLine(index2); //圣g

            //string index3 = test.Remove(2, 2);
            //Console.WriteLine(index3); //圣g诞节dsg来了,收到jgdddd

            Console.ReadKey();

        }
    }
}
原文地址:https://www.cnblogs.com/hao-1234-1234/p/6108211.html