473,378 Members | 1,343 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,378 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 9315
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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...

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.