其他分享
首页 > 其他分享> > 【蜕变之路】第23天 startsWith和endWith (2019年3月13日)

【蜕变之路】第23天 startsWith和endWith (2019年3月13日)

作者:互联网

      Hello,大家好!我是程序员阿飞!今天主要学习的内容是:startsWith方法和endWith方法。好了,直接进入正题。

    1、startWith方法

        作用:

            用于检测字符串是否以指定的前缀开始

        语法:

            public boolean startsWith(String prefix, int toffset)

            public boolean startsWith(String prefix)

        参数:

            prefix:前缀

            toffset:字符串中开始查找的位置

        返回值:

            如果字符串以指定的前缀开始,则返回 true;否则返回 false。

        实例:

            public class Test {    

                        public static void main(String args[]) {        

                          String Str = new String("www.runoob.com");        

                            System.out.print("返回值 :" );        

                            System.out.println(Str.startsWith("www") );        

                            System.out.print("返回值 :" );        

                            System.out.println(Str.startsWith("runoob") );        

                            System.out.print("返回值 :" );        

                            System.out.println(Str.startsWith("runoob", 4) );    

                    } 

                }

        

    2、endWith方法

        作用:

            用于检测字符串是否以指定的后缀开始

        语法:

            public boolean endWith(String suffix, int toffset)

            public boolean endWith(String suffix)

        参数:

            suffix:后缀

            toffset:字符串中开始查找的位置

        返回值:

            如果字符串以指定的后缀开始,则返回 true;否则返回 false。



                

标签:startsWith,13,endWith,String,System,public,out
来源: https://blog.51cto.com/12388374/2363060