Results 1 to 8 of 8
- 02-11-2010, 05:57 AM #1
Member
- Join Date
- Jan 2010
- Posts
- 9
- Rep Power
- 0
Extracting the text between two strings
Hi friends... I have a doubt in extracting the text between two strings. for example:
Begin THE EXCEPTION WAS HANDLED end
Now, How i need to find if the line has 'Begin' at the start and 'end' at the end of the string. after that, i need to extract the text 'THE EXCEPTION WAS HANDLED' alone,and store it somewhere.
How can i do that...?
It would be helpful if someone helps me with this query...Last edited by vidya; 02-11-2010 at 06:02 AM.
- 02-11-2010, 06:03 AM #2
Senior Member
- Join Date
- Mar 2009
- Location
- USA
- Posts
- 127
- Rep Power
- 0
take whole as one string
and use substring() to take the required string from the whole string.
- 02-11-2010, 06:17 AM #3
Senior Member
- Join Date
- Mar 2009
- Location
- USA
- Posts
- 127
- Rep Power
- 0
public class StringDemo {
public static void main(String[] args){
String string = "Begin THE EXCEPTION WAS HANDLED end";
System.out.println("String : " + string);
String substring = string.substring(0, 5);
System.out.println(substring);
String substring1 = string.substring(31, 35);
System.out.println(substring1);
String substring2 = string.substring(6, 31);
System.out.println(substring2);
}
output wud be:
run:
String : Begin THE EXCEPTION WAS HANDLED end
Begin
end
THE EXCEPTION WAS HANDLED
BUILD SUCCESSFUL (total time: 0 seconds)
- 02-11-2010, 07:04 AM #4
Member
- Join Date
- Jan 2010
- Posts
- 9
- Rep Power
- 0
Thanks for ur quick reply friend. i got the same idea of sub string previously(using 'regionMatches' method). but what u used here was the offset value to extract the sub string. but if we consider a huge paragraph, where we dont know that offset value, its not possible to use this method to retrieve the string right?
so what can be done for this?
- 02-11-2010, 07:08 AM #5
Senior Member
- Join Date
- Oct 2009
- Location
- California,US
- Posts
- 201
- Rep Power
- 4
well another option you can consider is using split method from the string class.
- 02-11-2010, 07:23 AM #6
Senior Member
- Join Date
- Mar 2009
- Location
- USA
- Posts
- 127
- Rep Power
- 0
There are lots of methods in String class.
For String manipulation, i suggest you to look at method available in String class.
- 02-11-2010, 09:18 AM #7
Member
- Join Date
- Jan 2010
- Posts
- 9
- Rep Power
- 0
@All
Thanks for ur suggestions. I wil try string class and get back if i find any difficulty.
- 02-11-2010, 11:04 PM #8
Similar Threads
-
searchin for more Strings in a Text
By gazale_m in forum New To JavaReplies: 8Last Post: 12-09-2008, 08:51 AM -
extracting text from jpeg
By Nicholas Jordan in forum Advanced JavaReplies: 0Last Post: 10-05-2008, 11:40 PM -
text box listeners and returning multiple strings from methods
By int80 in forum New To JavaReplies: 5Last Post: 07-18-2008, 04:30 PM -
Extracting JAR file
By Java Tip in forum Java TipReplies: 0Last Post: 02-08-2008, 09:17 AM -
text Strings to produce letters
By dc2acgsr99 in forum New To JavaReplies: 7Last Post: 01-29-2008, 08:08 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks