Grayson Carlyle
04-10-2003, 06:44 PM
I know the start and endpoint of the characters I need to pull from myString, now I just need to pull them. Help? :)
|
Click to See Complete Forum and Search --> : Need a javascript equilavent of vB Mid() Grayson Carlyle 04-10-2003, 06:44 PM I know the start and endpoint of the characters I need to pull from myString, now I just need to pull them. Help? :) Jona 04-10-2003, 06:48 PM ...Eh? You mean get the first and last letters of a string? pyro 04-10-2003, 06:48 PM I think you are looking for substr.... It is used like this: myNewString = myString.substr(0,5); That will take from position 0 to 5... Grayson Carlyle 04-10-2003, 06:50 PM That's exactly it, thanks :) Jona 04-10-2003, 06:51 PM :eek: Okay... :confused: Whatever.... pyro 04-10-2003, 06:51 PM No problem... ;) Cheers! Jona 04-10-2003, 06:53 PM So then, Dave, it would be myString.substr(4,5) right? pyro 04-10-2003, 06:54 PM Originally posted by Dave Clark Not quite... What are you talking about? :confused: This: myString = "testing"; myNewString = myString.substr(0,5); alert (myNewString); returns testi Jona 04-10-2003, 06:57 PM Um.. forget the argument... I'm gonna go experience all this for myself. (I know I know what it does, I just want to experiment.) Grayson Carlyle 04-10-2003, 06:57 PM I used indexOf to find 2 "constant" parts of a generated webpage. I then subtracted the second from the first to find the length of the area between them. I then used myString.value.substr(numstart, numlen) to get the string out that I wanted. My next step is to take this new string and remove the ","'s from it (since it's a number in the form of 2,546,700) But you don't need to post the code for that, I can think that much through with the knowledge I have now :) Grayson Carlyle 04-10-2003, 07:00 PM Heh, I'm not new to programming... just never used javascript before, so I'm learning by reading code. Predefined functions allude me until I see them used though pyro 04-10-2003, 07:02 PM So, are you saying it is syntactially incorrect to do this myNewString = myString.substr(0,5); alert (myNewString); or just that it doesn't take from position 0 to 5 but from position 0 to 5 more positions? Grayson Carlyle 04-10-2003, 07:02 PM Originally posted by Dave Clark To remove the commas from this: var str = "2,546,700"; it's easier to do it this way: str = str.split(",").join(""); Dave You can do that??? haha, sweet! Okay, thanks! pyro 04-10-2003, 07:04 PM So what I originally stated was correct. It will take from position 0 to 5 (5 more than 0) Although, I do agree with you. substring was probably what he was looking for... pyro 04-10-2003, 07:11 PM Ok, well... Thanks for straightening it out... ;) Cheers! Nedals 04-10-2003, 07:41 PM Originally posted by Dave Clark To remove the commas from this: var str = "2,546,700"; it's easier to do it this way: str = str.split(",").join(""); You could also do it this way.. str = str.replace(/\,/g,""); webdeveloper.com
Copyright Internet.com Inc., All Rights Reserved. |