471,123 Members | 845 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

substring syntax in javascript

Trying to debug someone else's javascript code. There is a line that
looks like this:

req = req.substring(req.length-2, req.length);
From what I can gather in their comments, they want to capture the last

two characters of the string "req".

I'm guessing that the above line won't do that, and they want to change
it to

req = req.substring(req.length-1, 2);

In other words, the parameters are starting position, and length. Is
that correct?
Dennis Hancy
Eaton Corporation
Cleveland, OH

Jul 23 '05 #1
6 9190
ASM
de*********@eaton.com wrote:
Trying to debug someone else's javascript code. There is a line that
looks like this:

req = req.substring(req.length-2, req.length);
From what I can gather in their comments, they want to capture the last two characters of the string "req".


I think it's what that do
req = req.substring(req.length-1, 2);

In other words, the parameters are starting position, and length. Is
that correct?


Exactly not !

foo.substring(start,end)
or, in this case :
foo.substring(start);

--
Stephane Moriaux et son [moins] vieux Mac
Jul 23 '05 #2
Lee
de*********@eaton.com said:

Trying to debug someone else's javascript code. There is a line that
looks like this:

req = req.substring(req.length-2, req.length);
From what I can gather in their comments, they want to capture the last

two characters of the string "req".

I'm guessing that the above line won't do that, and they want to change
it to

req = req.substring(req.length-1, 2);

In other words, the parameters are starting position, and length. Is
that correct?


No:

substring(indexA, indexB)

substring extracts characters from indexA up to
but not including indexB.

Jul 23 '05 #3
de*********@eaton.com wrote:
Trying to debug someone else's javascript code. There is a line that
looks like this:

req = req.substring(req.length-2, req.length);
From what I can gather in their comments, they want to capture the last

two characters of the string "req".

I'm guessing that the above line won't do that, and they want to change
it to

req = req.substring(req.length-1, 2);

In other words, the parameters are starting position, and length. Is
that correct?

No!

function lastNLetters(str,N){
return str.substring(str.length-N);
}
alert(lastNLetters("abcde",3));
Mick
Jul 23 '05 #4
Jc
de*********@eaton.com wrote:
req = req.substring(req.length-1, 2);

In other words, the parameters are starting position, and length. Is
that correct?


FYI: This could have been easily looked up in online/offline javascript
documentation. The group FAQ has links to online documentation.

comp.lang.javascript FAQ - http://www.jibbering.com/faq/

You are likely thinking of substr, whose second parameter is length.

Jul 23 '05 #5
de*********@eaton.com wrote:
Trying to debug someone else's javascript code. There is a line that
looks like this:

req = req.substring(req.length-2, req.length);
From what I can gather in their comments, they want to capture the last
^^ two characters of the string "req".

I'm guessing that the above line won't do that, [...]


But it does. RTFM, RTFFAQ and learn how to post.
PointedEars
--
http://members.ud.com/download/gold/
http://folding.stanford.edu/
http://alien.de/seti/
http://setiathome.ssl.berkeley.edu/
Jul 23 '05 #6
Use the MS Script Editor included free with MS Office 2002 and above,
for debugging Internet Explorer (IE).

This subject is of great interest to many JS developers, as there is no
obvious, low cost way to do sophisticated debugging in
IE6 other than to use the debugger described below, which is horribly
documented otherwise. I feel debugging is an important aspect of
projecting the useability of the language and needs to be made more
clear for new users.
Jeff Papineau
yo**@mandala.com
<FAQENTRY>

This is a page that describes how to install and use the MS Script
Editor to debug Javascript in Internet Explorer ( IE ). It has a
powerful debugger built into it that works really well for developers
supporting IE5+. This debugger/editor included with most versions of
Microsoft Office.

http://www.mandala.com/javascript/debug_javascript.html

..NET programmers may have better tools (VStudio) but this comes in
really handy for anyone developing with JSP and PHP and other dynamic
scripting languages which embed javascript, as well as any HTML page
using Javascript in Internet Explorer that needs a (almost) free
debugging environment.

</FAQENTRY>
de*********@eaton.com wrote:
Trying to debug someone else's javascript code. There is a line that
looks like this:

req = req.substring(req.length-2, req.length);
From what I can gather in their comments, they want to capture the last

two characters of the string "req".

I'm guessing that the above line won't do that, and they want to change
it to

req = req.substring(req.length-1, 2);

In other words, the parameters are starting position, and length. Is
that correct?
Dennis Hancy
Eaton Corporation
Cleveland, OH


Jul 23 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by joseph speigle | last post: by
15 posts views Thread by Duncan Allen | last post: by
3 posts views Thread by Rob R. Ainscough | last post: by
4 posts views Thread by Daviso | last post: by
3 posts views Thread by windandwaves | last post: by
2 posts views Thread by Derek Hart | last post: by
2 posts views Thread by JJA | last post: by
4 posts views Thread by Jean-Guy Mouton | last post: by

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.