Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Friday Programming Quiz [modified]

Friday Programming Quiz [modified]

Scheduled Pinned Locked Moved The Lounge
javascriptdebugginghelpquestion
24 Posts 12 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D David Stone

    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.

    M Offline
    M Offline
    Marc Clifton
    wrote on last edited by
    #21

    Why use Regex.Split instead of just csv1.Split(',') ? Marc

    Thyme In The Country

    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

    D 1 Reply Last reply
    0
    • M Marc Clifton

      Why use Regex.Split instead of just csv1.Split(',') ? Marc

      Thyme In The Country

      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

      D Offline
      D Offline
      David Stone
      wrote on last edited by
      #22

      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.

      M 1 Reply Last reply
      0
      • D David Stone

        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.

        M Offline
        M Offline
        Marc Clifton
        wrote on last edited by
        #23

        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

        Thyme In The Country

        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

        D 1 Reply Last reply
        0
        • M Marc Clifton

          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

          Thyme In The Country

          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

          D Offline
          D Offline
          David Stone
          wrote on last edited by
          #24

          Weird. 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.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups