c# - Parse through an array of strings to check how many times there's a value -
say have array of strings:
string[] arraytoparse = {2, g, r, g, b};
i need parse through array check how many times string present may end values this:
2 gg r b
so each time loop detects if there's string identical, "concatenates", add value list.
if take example: string[] arraytoparse2 = {2, q, t, t, u, u}
should end these values:
2 q tt uu
any anyone?
use linq (groupby
method) , string.join
:
string[] arraytoparse = {"2", "g", "r", "g", "b"}; string[] results = arraytoparse.groupby(x => x) .select(g => string.join(string.empty, g)) .toarray();
works both sample inputs.
Comments
Post a Comment