Solved

Get Substring between two other substrings

Posted on 2010-08-18
8
549 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…

757 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

21 Experts available now in Live!

Get 1:1 Help Now