473,547 Members | 2,653 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

substring syntax in javascript

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

req = req.substring(r eq.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(r eq.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 9331
ASM
de*********@eat on.com wrote:
Trying to debug someone else's javascript code. There is a line that
looks like this:

req = req.substring(r eq.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(r eq.length-1, 2);

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


Exactly not !

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

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

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

req = req.substring(r eq.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(r eq.length-1, 2);

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


No:

substring(index A, indexB)

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

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

req = req.substring(r eq.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(r eq.length-1, 2);

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

No!

function lastNLetters(st r,N){
return str.substring(s tr.length-N);
}
alert(lastNLett ers("abcde",3)) ;
Mick
Jul 23 '05 #4
Jc
de*********@eat on.com wrote:
req = req.substring(r eq.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.javas cript FAQ - http://www.jibbering.com/faq/

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

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

req = req.substring(r eq.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.co m
<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*********@eat on.com wrote:
Trying to debug someone else's javascript code. There is a line that
looks like this:

req = req.substring(r eq.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(r eq.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
52617
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 xtable set field1 = substring(field2, 1, 5) + substring(field3, 1, 5) + substring(field4, 1, 10)
6
3686
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: the file 'hostname.sql' is pl/pgsql main=> \e hostname.sql ERROR: syntax error at or near "http" at character 290
15
6060
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: string creationDateStr = string.Empty; string anotherStr = "";
3
1433
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 poor choice of language syntax? And why-o-why is it case sensitive? Is it just a carry over from light weight parsers? If we can't get out of...
4
8754
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 introduced in numberA will be different and make a conditional
3
9868
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 the exact names of the folders, etc...
2
3493
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: //Client/Names/Name/@display_name So I have tried: substring(//Client/Names/Name/@display_name,1,3)
2
2490
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 the array is an object itself but what is this syntax of the consecutive double quotes inside the brackets ?
4
4901
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 variable to use it elsewhere? I thought I could use the function split and create an array but I have different string lengths with a variable number of...
0
7510
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7437
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7797
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6032
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5362
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3493
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3473
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1050
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
748
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.