c# - split string in substring using a string delimiter -
i've string message like
"trx00 abcd 20150921 "
or (n) times string, i.e.
"trx00 abcd 20150921 trx00 abcd 20150921 trx00 abcd 20150921 "
etc..
how can split string in (n) strings using "trx"
@ beginning of each substring delimiter?
i want take delimiter "trx"
in substring.
i've done following it's doesn't work well..
string msg = "trx00 abcd 20150921 trx00 abcd 20150921 trx00 abcd 20150921 "; string[] _msg; string pattern = "(trx)"; string msg2 = ""; if(msg.contains("trx")) { _msg = regex.split(msg, pattern); foreach (string ok in _msg) { msg2 = ok; messagebox.show(msg2); } }
the expected result should array of substrings like:
{ "trx00 abcd 20150921 ", "trx00 abcd 20150921 ", etc.. }
you can use pattern in code instead of (trx)
:
(?!^)(?=trx)
it split on trx long isn't @ start of string , returns:
trx00 abcd 20150921
trx00 abcd 20150921
trx00 abcd 20150921
Comments
Post a Comment