Check if string ends with certain pattern

后端 未结 5 1873
予麋鹿
予麋鹿 2020-12-03 00:11

If I have a string like:

This.is.a.great.place.too.work.

or:

This/is/a/great/place/too/work/

than my prog

5条回答
  •  天命终不由人
    2020-12-03 01:07

    You can use the substring method:

       String aString = "This.is.a.great.place.too.work.";
       String aSubstring = "work";
       String endString = aString.substring(aString.length() - 
            (aSubstring.length() + 1),aString.length() - 1);
       if ( endString.equals(aSubstring) )
           System.out.println("Equal " + aString + " " + aSubstring);
       else
           System.out.println("NOT equal " + aString + " " + aSubstring);
    

提交回复
热议问题