Subtracting string arrays

Discussion in 'Ruby' started by Brian Scott, Feb 13, 2010.

  1. Brian Scott

    Brian Scott Guest

    Hello,

    I am having am issue subtracting two arrays with string elements.

    I have the following?

    a = ["StringA", "StringB", "StringC"]

    b = ["StringC"]

    How to I subtract the two arrays so I have a new array with the
    following?

    result = ["StringA", "StringB"]



    Thanks
    --
    Posted via http://www.ruby-forum.com/.
     
    Brian Scott, Feb 13, 2010
    #1
    1. Advertising

  2. Brian Scott

    Gary Wright Guest

    On Feb 12, 2010, at 8:43 PM, Brian Scott wrote:
    > How to I subtract the two arrays so I have a new array with the
    > following?
    >
    > result = ["StringA", "StringB"]


    You've almost answered your own question:

    >> a = ["StringA", "StringB", "StringC"]

    => ["StringA", "StringB", "StringC"]
    >>

    ?> b = ["StringC"]
    => ["StringC"]
    >> a - b

    => ["StringA", "StringB"]
    >>


    Gary Wright
     
    Gary Wright, Feb 13, 2010
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brian Henry
    Replies:
    6
    Views:
    16,178
    Brian Henry
    Nov 19, 2003
  2. =?Utf-8?B?TWFubnkgQ2hvaGFu?=

    subtracting days from date

    =?Utf-8?B?TWFubnkgQ2hvaGFu?=, Nov 8, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    27,505
    =?Utf-8?B?QmlsbCBCb3Jn?=
    Nov 9, 2004
  3. Philipp
    Replies:
    21
    Views:
    1,139
    Philipp
    Jan 20, 2009
  4. Jason Lillywhite

    subtracting arrays

    Jason Lillywhite, Jun 12, 2008, in forum: Ruby
    Replies:
    3
    Views:
    131
    Jason Lillywhite
    Jun 12, 2008
  5. Jonas Nilsson

    Subtracting arrays of floats.

    Jonas Nilsson, Sep 16, 2003, in forum: Perl Misc
    Replies:
    12
    Views:
    166
    Tassilo v. Parseval
    Sep 17, 2003
Loading...

Share This Page