Now that everyone has gone off track to your question :)
You'll need to parse out the values from the string (as ints, strings, characters, whatever). You can then use Linq to get the union of the two sets, for example
String string1 = "1,2,3";
String string2 = "3,4,5";
String[] s1Parts = string1.Split(',');
String[] s2Parts = string2.Split(',');
IEnumerable<String> union = s1Parts.Union(s2Parts);
foreach (String s in union) {
Console.Write(s);
}
Momerath
Nearly a Senior Poster
3,386 posts since Aug 2010
Reputation Points: 1,232
Solved Threads: 558
I read in this post that using + to concatenate strings is:
about 25% faster than using string.join()
about 15% faster than using string.format()
and about 10% faster than using a stringbuilder
Haven't actually tested it myself but this is some food for thought.
It is, so I tested it. My results:[INDENT]Timer frequency in ticks per second = 2929775
Timer is accurate within 341 nanoseconds
Using + took 26,931,729 ticks
Using Join took 26,931,729 ticks
Using Concat took 27,652,841 ticks
Using Format took 164,192,838 ticks
Using Stringbuilder took 46,204,923 ticks
[/INDENT]That's for 100,000,000 million string 'concats'. The difference between the fastest (+ and Join) and the slowest (Format) is 46.8 seconds. Stringbuilder is comparable to the fastest if you take the Clear of the object out of the timing loop.
Momerath
Nearly a Senior Poster
3,386 posts since Aug 2010
Reputation Points: 1,232
Solved Threads: 558
Adding a comma will allow the use of distinct() (assuming certain namespaces are allowed):
using System;
using System.Linq;
namespace DW_411407_CS_CON
{
class Program
{
static void Main(string[] args)
{
string str1 = "1,2,3";
string str2 = "3,4,5";
Console.WriteLine(string.Join(",",(str1+','+str2).Split(',').Distinct().ToArray()));
}
}
}
thines01
Postaholic
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402