Issue
I have a string that look like:
data = ABSIFHIEHFINE -2938 NODFNJN {[somedate]} oiejfoen
I need to pull {[somedate]}
only with {[]} included.
I tried to do data.substring(0, data.indexOf(']}'))
to remove the end of the string but it is also removing the symbols that I need to keep
Solution
I need to pull {[somedate]} only with {[]} included.
def data = 'ABSIFHIEHFINE -2938 NODFNJN {[somedate]} oiejfoen'
// you could do error checking on these to ensure
// >= 0 and end > start and handle that however
// is appropriate for your requirements...
def start = data.indexOf '{['
def end = data.indexOf ']}'
def result = data[start..(end+1)]
assert result == '{[somedate]}'
Answered By - Jeff Scott Brown
Answer Checked By - Terry (JavaFixing Volunteer)