Solved

Get Substring between two other substrings

Posted on 2010-08-18
8
556 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
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 
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
 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Spring Framework HTTPSession management 1 45
How to convert from xls to xlsx using java 7 55
Java basic valueOf question 1 29
java mysql insert application 14 28
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
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…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

828 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