c# - Extracting an unknown string between two known strings -
i have following string:
string nextevent = "[[\"nextdata\", \"random message\"], [\"moreinfo\", {\"num\": 3204}]]"
i need "random message" (without quotes) seperate string. now, easy if random message constant, it's not. let's it's generated through user input, , different in value , length every time.
how go extracting message there? i've tried using substring indexof, got wrong results every time, it's quite confusing.
if you'd 'brute force' method:
string nextevent = "[[\"nextdata\", \"random message\"], [\"moreinfo\", {\"num\": 3204}]]"; string tmp = nextevent.trim(new char[] { '[', ']' }); string[] sa = tmp.split(','); string rndmsg = sa[1].trim().trim(new char[] { '[', ']', '\"' });
Comments
Post a Comment