Usage of substring () and indexof () in Java

Source: Internet
Author: User


Usage of substring () and indexof () in "Javase" Java

/** * @ details about the use of substring () and indexof (), how to combine  *  @author   Night Legends  * */public  Class test {public static void main (String[] args)  {String str =   "My name is xiaoye ' S chuanshou"; str = str.substring (6);//  Str=str.substring (Int  beginindex); intercepts the string of length beginindex from the first letter of STR and assigns the remaining string to Str;system.out.println (str) ; str = str.substring (2, 10);//  intercepts the string from Beginindex to Endindex at the end of STR and assigns it to STR; The value that contains the Beginindex location, but does not contain the value of Endindex) System.out.println (str); string sr =  "My name  is xiaoye ' S chuanshou"; string sx =  "is"; Int index = sr.indexof (SX);// If present, returns the index position System.out.println (index+ "<<<<") where the string begins to appear; Int index2 = sr.indexof (SX, &NBSP;3);//This means starting at index position 3, looking for a string sx= "is", and then returning the index position where the string starts to appear System.out.println (index2+ "<<<<<"); String str2= "<12453>123"; SyStem.out.println (Str2.indexof ("wwww"));//If it does not contain a string wwww, then it is proved that there is no location in the entire index, returning to the Guardian -1system.out.println (Str2.substring ( Str2.indexof ("123") +1,9) + "<<<<<<");//The above code, first Str2.index ("123") returned is 7, representing the beginning of the 7th bit to appear the entire string//plus 1, The meaning of the representation is that the index position 8//from index position 8 to 9, because substring is not the end of the head, so substring (8,9) takes out 2}.


This article from "Promise always attached to the small wood 、、、" blog, please be sure to keep this source http://1936625305.blog.51cto.com/6410597/1556999

Usage of substring () and indexof () in Java

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.