C#——String.IndexOf方法与Array.IndexOf方法的异同

           相同:返回值都为int类型,没找到返回值都为-1

            (1)//IndexOf方法从左到右查找子串在母串中的索引值


            String a = "abcdefg";
            int x=a.IndexOf("b");    //x=1
            int y = a.IndexOf("c",2,4);    //y=2

           (2) //IndexOf方法从数组中查找指定对象的角标


            String []b=new String[10];
            b[0]="aa";
            b[1] = "bb";
            b[2] = "cc";
            b[3] = "dd";
            int z = Array.IndexOf(b,"cc");   //z=2

猜你喜欢

转载自blog.csdn.net/lmm0513/article/details/88773562