Friday Programming Quiz [modified]
-
LINQ: (Note: Completely untested. I haven't set up Visual Studio on my new laptop yet. ;P Should work though.)
string GetCsvIntersection(string csv1, string csv2)
{
var list1 = new List<String>(Regex.Split(csv1, ","));
var list2 = new List<String>(Regex.Split(csv2, ","));var result = new StringBuilder(); foreach (string item in list1.Intersect(list2)) { result.AppendFormat("{0},", item); } return result.Remove(result.Length - 1, 1).ToString();
}
Last modified: 2hrs 8mins after originally posted -- Yeah. Okay. LINQ still isn't as cool as Javascript
Oh geez... the forum keeps spinning... you'll take care o f it i'm sure, c'ause ... yeah, i neede this. *cough* anyway good job finding the bug. -Shog9 on...a Firefox bug.
Why use Regex.Split instead of just csv1.Split(',') ? Marc
People are just notoriously impossible. --DavidCrow
There's NO excuse for not commenting your code. -- John Simmons / outlaw programmer
People who say that they will refactor their code later to make it "good" don't understand refactoring, nor the art and craft of programming. -- Josh Smith -
Why use Regex.Split instead of just csv1.Split(',') ? Marc
People are just notoriously impossible. --DavidCrow
There's NO excuse for not commenting your code. -- John Simmons / outlaw programmer
People who say that they will refactor their code later to make it "good" don't understand refactoring, nor the art and craft of programming. -- Josh SmithBecause Regex.Split takes a String. String.Split needs a char array. And so I didn't want to construct a whole char[]. ;P There's no other good reason.
Mandrake, do you realize that in addition to fluoridating water, why, there are studies underway to fluoridate salt, flour, fruit juices, soup, sugar, milk, ice cream. Ice cream, Mandrake. Children's ice cream.
-
Because Regex.Split takes a String. String.Split needs a char array. And so I didn't want to construct a whole char[]. ;P There's no other good reason.
Mandrake, do you realize that in addition to fluoridating water, why, there are studies underway to fluoridate salt, flour, fruit juices, soup, sugar, milk, ice cream. Ice cream, Mandrake. Children's ice cream.
David Stone wrote:
String.Split needs a char array.
Obviously, the documentation and Intellisense does not match the implementation, as:
string foo="a,b,c"; string\[\] foo2=foo.Split(',');
Compiles fine. Unless there's some implicit conversion to char[]? I use the above syntax all the time! :~ Marc
People are just notoriously impossible. --DavidCrow
There's NO excuse for not commenting your code. -- John Simmons / outlaw programmer
People who say that they will refactor their code later to make it "good" don't understand refactoring, nor the art and craft of programming. -- Josh Smith -
David Stone wrote:
String.Split needs a char array.
Obviously, the documentation and Intellisense does not match the implementation, as:
string foo="a,b,c"; string\[\] foo2=foo.Split(',');
Compiles fine. Unless there's some implicit conversion to char[]? I use the above syntax all the time! :~ Marc
People are just notoriously impossible. --DavidCrow
There's NO excuse for not commenting your code. -- John Simmons / outlaw programmer
People who say that they will refactor their code later to make it "good" don't understand refactoring, nor the art and craft of programming. -- Josh SmithWeird. Huh. Then there's really no reason (here) to use Regex.Split. Go figure.
Oh geez... the forum keeps spinning... you'll take care o f it i'm sure, c'ause ... yeah, i neede this. *cough* anyway good job finding the bug.
-Shog9 on...a Firefox bug.