473,396 Members | 2,113 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,396 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 9318
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: ja | last post by:
Hello, I am trying to combine/substring parts of three different fields into one. For example, in sql, the syntax is as follows: Once the extra field has been added to the table, update...
6
by: joseph speigle | last post by:
hi, Does anybody know offhand what is the correct way to use substr to extract the domain name from a client_referer column as logged by mod_pgsqllog (httpd module), by correcting the following: ...
15
by: Duncan Allen | last post by:
Hi, Using C# I'm trying to use the substring method of a string variable but it just generates an "error: 'variable.Substring' does not exist " exception - how do I fix this ? code example: ...
3
by: Rob R. Ainscough | last post by:
What sick saddistic person came up with the JavaScript language syntax? And was it the same person (or group of people) that came up with the HTML syntax?? OMG, has no one noticed this hopeless...
4
by: Daviso | last post by:
Hi. I hava an input like this <td><input name=numberA> </td> and a button with a javascript function in onclick event. I want to control that the first element of the value I have...
3
by: windandwaves | last post by:
Hi Folk I have the following string: http://www.myurl.com/folderbit/moerfiasdfsadf/sdaf/01354.jpg and I want to extract the filename from it. Do you know how to do this, if I don't know...
2
by: Derek Hart | last post by:
This is probably so simple. I am doing a SelectSingleNode to get the value from an XPath statement, and I simply want the 3 leftmost characters. I cannot get the syntax to work: ...
2
by: JJA | last post by:
I'm looking at some code I do not understand: var icons = new Array(); icons = new GIcon(); icons.image = "somefilename.png"; I read this as an array of icons is being built. An element of...
4
by: Jean-Guy Mouton | last post by:
Hello, I am teaching myself Dom scripting with Javascript. I do not understand how to get a substring. If I have strings in the form: "This is string number 1" How can I put "1" into a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.