Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# Get Substring between two other substrings

Posted on 2010-08-18
Medium Priority
563 Views
Searching inside a string for substring. I only know the left and rigth border substrings. Example:
Searching for the substring between "abc" and "ghi". How to do that ?
0
Question by:michael_ch
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 23

Assisted Solution

Ajay-Singh earned 200 total points
ID: 33466031
use contains() function
0

LVL 40

Assisted Solution

Gurvinder Pal Singh earned 200 total points
ID: 33466087
String str = "abcasdasdasdghi";;
int begin = str.indexOf ("abc") + 3;
int end = str.indexOf("ghi");
String requredStr = str.substring(begin, end);
0

LVL 23

Assisted Solution

Kamaraj Subramanian earned 200 total points
ID: 33466123
0

LVL 86

Expert Comment

ID: 33466714
>>Get Substring between two other substrings

What are you going to do with it when you've go it?
0

LVL 10

Assisted Solution

Hegemon earned 200 total points
ID: 33468819
regexps ?
0

LVL 92

Accepted Solution

objects earned 1000 total points
ID: 33470821
String substring = str.substring(str.indexOf(left)+left.length(), str.lastIndexOf(right));
0

LVL 10

Assisted Solution

gordon_vt02 earned 200 total points
ID: 33475096
Pattern p = Pattern.compile(".*abc(.*)ghi.*");
String input = "12343234abcsubstringghi1209432890324";
Matcher m = p.matcher(input);
String substring;
if (m.matches()) {
substring = m.group(1);
}
0

Author Closing Comment

ID: 33598478
Thanks a lot, tried your solution objects. Works !
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula wâ€¦
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Booleâ€¦
The viewer will learn how to implement Singleton Design Pattern in Java.
###### Suggested Courses
Course of the Month5 days, 11 hours left to enroll