473,787 Members | 2,989 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

extract number from a string - get 13 from 'product13'

Hello,
I am trying to figure out how to get a number (always an int) from a
string.

so if i have something like
<input type="text" id="product13" name="product13 " onblur="return
somefunc(this); " />

then have a function
somefunc(elemen t){
//extract number from element.name and get 13 in this example
// do other stuff
}

Thanks in advance,
Chuck

Nov 1 '05 #1
5 28820
chuck wrote:
Hello,
I am trying to figure out how to get a number (always an int) from a
string.

so if i have something like
<input type="text" id="product13" name="product13 " onblur="return
somefunc(this); " />

then have a function
somefunc(elemen t){
//extract number from element.name and get 13 in this example
// do other stuff
}

Thanks in advance,
Chuck

I found a function to do this, so i thought i would post it
function getNo(stringNo)
{var parsedNo = "";
for(var n=0; n<stringNo.leng th; n++)
{var i = stringNo.substr ing(n,n+1);
if(i=="1"||i==" 2"||i=="3"||i== "4"||i=="5"||i= ="6"||i=="7"||i =="8"||i=="9"|| i==
"0")
parsedNo += i;
}
return parseInt(parsed No);
}
Nov 1 '05 #2
chuck wrote:
Hello,
I am trying to figure out how to get a number (always an int) from a
string.

so if i have something like
<input type="text" id="product13" name="product13 " onblur="return
somefunc(this); " />

then have a function
somefunc(elemen t){
//extract number from element.name and get 13 in this example
// do other stuff
}


<input type="text" id="product13" name="product13 " onblur="
alert(this.id.r eplace(/\D/g,''));
">

Replaces all the non-digit characters in the id with an empty string
(essentially nothing) but returns all the digits in the id:

id="product13A1 3" ==> 1313


If you just want digits at the end:

alert(this.id.m atch(/\d+$/));

id="product13A1 3" ==> 13

--
Rob
Nov 1 '05 #3

Well:

<input type="text" name="product13 " onblur="somefun c(this)/>

function somefunction(el ) {
mynumber=Number (el.name.slice(-2));
}

//many ways really

Danny
Nov 1 '05 #4
"chuck" <no****@somedom ain.com> wrote in message news:11******** *****@corp.supe rnews.com...
chuck wrote:
Hello,
I am trying to figure out how to get a number (always an int) from a string.

so if i have something like
<input type="text" id="product13" name="product13 " onblur="return somefunc(this); " />

then have a function
somefunc(elemen t){
//extract number from element.name and get 13 in this example
// do other stuff
}

Thanks in advance,
Chuck

I found a function to do this, so i thought i would post it
function getNo(stringNo)
{var parsedNo = "";
for(var n=0; n<stringNo.leng th; n++)
{var i = stringNo.substr ing(n,n+1);
if(i=="1"||i==" 2"||i=="3"||i== "4"||i=="5"||i= ="6"||i=="7"||i =="8"||i=="9"|| i== "0")
parsedNo += i;
}
return parseInt(parsed No);
}


Or, less complicated:

function somefunc(obj)
{
return obj.id.match(/\d+/)[0];
}

If the number is always at the end of the id, you can better use:

obj.id.match(/\d+$/)[0];

Nov 1 '05 #5
chuck wrote:
<input type="text" id="product13" name="product13 " onblur="return
somefunc(this); " />


Be sure to declare this as XHTML and to serve as application/xhtml+xml.
`<... />' is most certainly a syntax error in HTML (depending on the
following content). The HTML Compatibility Guidelines of the XHTML 1.0
Specification do take this into account, instead the recommendations
rely merely on error-correction by user agents.

<http://validator.w3.or g/>
<http://www.dodabo.de/html+css/tests/shorttag.html>
<http://translate.google.com/translat...ml&langpair=de
en&hl=de&ie=Unk nown&oe=ISO-8859-1>
PointedEars
Nov 1 '05 #6

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

Similar topics

12
2403
by: levent | last post by:
What is an elegant way (using std::stream's) to extract number of white-space separated entries in a given line of a formatted text file? e.g.: Take this section of a file, 1 2.78 4 5 -0.003 <tab> 7.1d5 9 40 <tab> 2.e5 -10 ....
3
3417
by: Tracey | last post by:
I'm learning C++ and was stuck when writing code to convert a negative decimal number string to a hexdecimal number. For example, suppose the function interface is defined as: int atoi( const char*, size_t radix) One input string is "-1234" and radix is 16. How to get the correct hexdecimal integer? Can anyone help ? Thanks in advance!
7
1732
by: jack | last post by:
Hello, I need to get the time down the the 0.1 second in a number string. Example 09-06-03 13:45 23.4 Seconds To "0906031345234"
1
1760
by: | last post by:
Hiya, I need to extract a string (ascii) from a buffer, my buffer is dim buf(1023) as byte This buffer containg an "array" of type xxx type xxx is defined in C as follows
1
3665
by: nkg1234567 | last post by:
I'm trying to extract HTML from a website in the form of a string, and then I want to extract particular elements from the string using the substr function: here is some sample code that I have thus far: use HTTP::Request::Common; use LWP::UserAgent; use LWP::Simple; $ua = LWP::UserAgent->new;
34
2751
by: Umesh | last post by:
I want to extract a string abc*xyz from a text file. * indicates arbitrary no. of characters. I'm only able to do it when the string has definite no. of characters or the string length is constant: i.e. five or the string is abc????? xyz How can i generalize it for any length of the string?
3
23795
by: ccarter45 | last post by:
I really need help with this. Your tips are greatly appreciated: import java.util.Scanner; public class PhoneNumbers { public static void main(String args){ Scanner input; Scanner scan = new Scanner(System.in);//get user input
2
4690
by: MaryJolly | last post by:
I want to extract number part from a string. I am doing project in VB6 and my MSFlexGrid control contains certain codes in the first column.eg. EC101,CS104,etc. I want to extract the number part from the text.
9
3904
by: korea saeed | last post by:
how can i convert number string to number?(without using parsint)
0
9655
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9964
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8993
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7517
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6749
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5398
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4067
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2894
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.