string - Java Parsing outputted message -


i need parse strings in efficient way. have line

d[date-string] t[time-string] n[name-string] m[message-string] 

needs parsed 4 strings respectively,

private string time; //would equal time-string private string date; //would equal date-string private string name; //would equal name-string private string message; //would equal message-string 

is there easy way this?

you can use regex , groups match , extract kind of data: example, like:

    pattern p = pattern.compile("d(\\w+) t(\\w+) n(\\w+) m(\\w+)");     matcher m = p.matcher(yourstring);     if (m.matches()){         string d = m.group(1);         string t = m.group(2);         string n = m.group(3);         string w = m.group(4);     } 

the patterns within parentheses saved groups, can extract after match (it starts 1, since 0 whole match). have change characters , patterns want accept.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -