473,395 Members | 1,652 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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

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)

Nov 19 '06 #1
2 2394

Daniel Reardon wrote:
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)
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

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

var ticker = 'http://caps.fool.com?ticker=MSFT';
var len = ticker.length;
var id = ticker.substr(len-4,len);

if you want it to work for you.

There's a ton of documentation on basic methods like this. I suggest
for the future you look this sort of thing up at w3schools.com or in a
good reference like the O'Reilly guide before bringing your question
here - it'll save everybody a lot of time.

Nov 19 '06 #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.
Nov 20 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ari | last post by:
we have a strange problem with oracle dynamic sql method 4. when selecting a substr we expect to, and normally, receive from oracle in the describe select list (SELDSC) the length of the...
2
by: Cal Lidderdale | last post by:
Can I do this? Can't find any ref. select substr(col1,1,3) from table ... select col1 from table The column contains ABC123, DEF456, etc I want: ABC DEF
7
by: entropy123 | last post by:
My problem is with the following test code: #include<string>; std::string TestBuff; TestBuff.append("A + B <==> C + D"); std::cout << "TestBuff.length():" << TestBuff.length() << endl;...
18
by: Jen | last post by:
I'm using Microsoft's own VB.NET FTP Example: http://support.microsoft.com/default.aspx?scid=kb;en-us;832679 I can get the program to create directories, change directories, etc., but I can't...
6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
1
by: db55 | last post by:
This script doesn't work. Why? UPDATE SET = LTRIM(SUBSTRING(, 1, convert(bigint, CHARINDEX(',', Comments)-1))) WHERE NOT( IS NULL) AND LEN() > 8 Basically, I'm trying to...
6
by: sks | last post by:
Hi, Here is a small program that is wrtten to simply use substr. When the second parameter in substr (length of the string to be extracted) is lesser than 0, the output is the entire string (I'm...
4
by: Jean-François Michaud | last post by:
Hello, I've been looking at this for a bit now and I don't see what's wrong with the code. Can anybody see a problem with this? Here is an XSLT snippet I use. <xsl:template match="graphic">...
4
by: zion4ever | last post by:
Hello good people, Please bear with me as this is my first post and I am relative new to ASP. I do have VB6 experience. I have a form which enables users within our company to do an intranet...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.