【蛻變之路】第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。



                

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章