Solved

Get Substring between two other substrings

Posted on 2010-08-18
8
550 Views
Last Modified: 2013-11-23
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
Comment
Question by:michael_ch
8 Comments
 
LVL 23

Assisted Solution

by:Ajay-Singh
Ajay-Singh earned 50 total points
ID: 33466031
use contains() function
0
 
LVL 40

Assisted Solution

by:gurvinder372
gurvinder372 earned 50 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

by:Kamaraj Subramanian
Kamaraj Subramanian earned 50 total points
ID: 33466123
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 33466714
>>Get Substring between two other substrings

What are you going to do with it when you've go it?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 10

Assisted Solution

by:Hegemon
Hegemon earned 50 total points
ID: 33468819
regexps ?
0
 
LVL 92

Accepted Solution

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

Assisted Solution

by:gordon_vt02
gordon_vt02 earned 50 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

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This video teaches viewers about errors in exception handling.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now