File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Substring Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Substring " Watch "Substring " New topic
Author

Substring

deep pal
Greenhorn

Joined: Mar 19, 2008
Posts: 6
hi i have following string -"[ValidationMessage: messageCode:Effective Entry Date in Batch Header cannot be more than 60 days in the future. context:null]"

i want to extract "Effective Entry Date in Batch Header cannot be more than 60 days in the future." part from this string

what is best way to do it.???
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32667
    
    4
Several ways to do it.

You can try the String.split() method with regular expressions for punctuation, but you might lose the . at the end.

You could try
int start = myString.indexOf(":") + 1;
int end = myString.indexOf(".", start) + 1;
String message = myString.substring(start, end);

Or
int start = myString.indexOf("Effective"); etc.

There are probably other ways to do it, but they will all depend on the message String always being in a similar format. Changing "Effective" to "Intended" will make it impossible to find your substring.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Substring
 
Similar Threads
Short/Long day?
difference in days
problem with "Expires" header
48 Hour rule again.
Help for future date?