I have the following string in C#.
"aaa,bbbb.ccc|dddd:eee"
I then split it with new char[] {',','.','|',':'}. How would I rejoin this string in the same order as before with the same characters? So the list would end up the exact same as it was before.
EXAMPLE
string s = "aaa,bbbb.ccc|dddd:eee";
string[] s2 = s.Split(new char[] {',','.','|',':'});
// now s2 = {"aaa", "bbbb", "ccc", "dddd", "eee"}
// lets assume I done some operation, and
// now s2 = {"xxx", "yyy", "zzz", "1111", "222"}
s = s2.MagicJoin(~~~~~~); // I need this
// now s = "xxx,yyy.zzz|1111:222";
EDIT
the char[] in above sample just sample, not in same order or even will not all appear in same time in real world.
EDIT
Just a thought, how about use Regex.split, then first split by char[] get a string[], then use not the char[] to split get another string[], later just put them back. Maybe work but I do not know how to code it.
It might be easier to do this with the Regex class:
Where DoSomething is a method or lambda that transforms the item in question, e.g.:
For this example the output string for “aaa,bbbb.ccc|dddd:eee” would be “AAA,BBBB.CCC|DDDD:EEE”.
If you use a lambda you can very easily keep state around, like this:
Outputs:
It just depends on what kind of transformation you’re doing to the items.