Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Can't get a substr() or substring() of a passed in variable

Reply
Thread Tools

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

 
 
Daniel Reardon
Guest
Posts: n/a
 
      11-19-2006
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)

 
Reply With Quote
 
 
 
 
Richard Cornford
Guest
Posts: n/a
 
      11-20-2006
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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"Variable variable name" or "variable lvalue" mfglinux Python 11 09-12-2007 03:08 AM
if instance variable get initialize after assigning some values or after constructor then when does static variable get initialize Tony Morris Java 3 02-04-2006 08:39 AM
Session("passed") = Session("passed") + 1 error dee ASP .Net 9 04-15-2005 10:47 AM
Just to share my happyness: Passed today 70-290! First try...and passed ;) Hugo Sousa MCSE 12 04-02-2005 12:16 AM
How do I scope a variable if the variable name contains a variable? David Filmer Perl Misc 19 05-21-2004 03:55 PM



Advertisments