| Welcome to WebmasterWorld Guest from 126.96.36.199 |
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
|Become a Pro Member|
|Getting a part of a string in JS|
var text1="string to process";
var whatever = text1.substring(3, 9);
here is a example page that may help:
var showMe = text1.substring(1, 4);
<form name="form1" onSubmit="trimS(); return false">
<input type="text" name="textbox1">
<input type="text" name="textbox2">
It worked! I thought that I'd seen it before, but I wasn't sure. Thanks Korkus!
I use the substring() method almost exclusivley over substr() or slice().
Substring can be used to get from a start char to the end of the string also, by just passing it the start char, i.e.,
string.substring(4); will get from char 4 to string.length.
The other thing I use it for alot is to snip out or replace known sections of an unparsed string, i.e.,
var a = string.substring(0, string.indexOf("example")); var b = string.substring(string.indexOf("example") + "example".length); string = a + "this used to say 'example'" + b;
All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved