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

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -