Can't get a substr() or substring() of a passed in variable

Discussion in 'Javascript' started by Daniel Reardon, Nov 19, 2006.

  1. All,

    I'm sure that this is an old question, but I'm having problems getting
    a substring of a passed in variable. I can do other string
    manipulation with it such as concatonation, but I'm really trying to
    get everything after the = assigned to the id variable (i.e. set MSFT
    to the id variable). Any help would be appreciated it.


    'ticker' variable passed in is =
    'http://caps.fool.com/Ticker.aspx?source=icaedilnk9950012&ticker=MSFT''

    The first alert(ticker) work perfect and returns the entire string
    above.

    ####Non-Working
    Example####________________________________________________
    function enhanceTickerLinks(ticker)
    {
    alert(ticker)
    var id
    id = ticker.substr(5)
    alert(id)
     
    Daniel Reardon, Nov 19, 2006
    #1
    1. Advertising

  2. David Golightly wrote:
    > Daniel Reardon wrote:
    >> I'm sure that this is an old question, but I'm having
    >> problems getting a substring of a passed in variable.
    >> I can do other string manipulation with it such as
    >> concatonation, but I'm really trying to get everything
    >> after the = assigned to the id variable (i.e. set MSFT
    >> to the id variable). Any help would be appreciated it.
    >>
    >>
    >> 'ticker' variable passed in is =
    >>

    'http://caps.fool.com/Ticker.aspx?source=icaedilnk9950012&ticker=MSFT''
    >>
    >> The first alert(ticker) work perfect and returns the entire
    >> string above.
    >>
    >> ####Non-Working
    >> Example####________________________________________________
    >> function enhanceTickerLinks(ticker)
    >> {
    >> alert(ticker)
    >> var id
    >> id = ticker.substr(5)
    >> alert(id)

    >
    > That's because the parameter you're using is wrong.
    >
    > String.substr(start, length)
    >
    > if argument length is missing, it's assumed to be the
    > length of the string


    The second argument to - substr - is optional.

    > Firefox accepts negative indices to read from the end of
    > the string, but IE isn't that advanced.

    <snip>

    IE does not appear to have any problems with - substr - only being given
    one argument.

    The most likely explanation here is that the question as asked is
    substantially misleading and rather than being passed a string as its
    argument the function is being passed a reference to the - location -
    object, which does have a - toString - method (so will show the URL text
    with - alert(location) - and may be concatenated to strings using the -
    + - operator) but dos not have - substring - or substr - methods.

    Richard.
     
    Richard Cornford, Nov 20, 2006
    #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. dee
    Replies:
    9
    Views:
    539
    Joseph Byrns
    Apr 15, 2005
  2. Anand
    Replies:
    2
    Views:
    934
    Anand
    Sep 11, 2003
  3. Joshua Muheim

    Substring like in PHP's substr()?

    Joshua Muheim, Apr 9, 2007, in forum: Ruby
    Replies:
    5
    Views:
    146
    Joshua Muheim
    Apr 9, 2007
  4. Replies:
    3
    Views:
    231
    Sherm Pendley
    Aug 3, 2005
  5. Alextophi
    Replies:
    2
    Views:
    159
    Alextophi
    Sep 14, 2005
Loading...

Share This Page