• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Substring

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.???
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic