View Single Post
Old 09-10-2012, 05:33 PM   PM User | #5
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,662
Thanks: 4
Thanked 2,452 Times in 2,421 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Simply use indexOf on string. It accepts a string as well:
PHP Code:
        System.out.println("Starting position of your substring in string: " longSt.indexOf(substring)); 
Note in this example you have here, the starting position is 3, not four. But that differs from the starting index versus the position within the string. Arrays are 0 based in java, so that would indicate that the character array for this string starts its substring in position 3, which is the fourth character of the string.

Once you get the index you can use that as a part of the substring method to determine start and end positions (with length's involved).
Fou-Lu is offline   Reply With Quote