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