PDA

View Full Version : stringstart and stringend



JANLEE
07-26-2005, 08:51 PM
Hi,

How I do to see in a lot of text the stringstart and stringends?

Thanks

JanLee

hourang
07-26-2005, 09:16 PM
var thestring="This is soo cool";
var charlength = 1;
var stringstart = thestring.substr(0,charlength);
var stringend = thestring.substr(thestring.length-charlength,charlength);

alert(stringstart);
alert(stringend);

this will give you the first and last letter in a string, changing the charlength value will give you more letters.

JANLEE
07-26-2005, 10:13 PM
Thank you Hourang!

But... if there is not blank spaces? like this:

1122474436/*-http://www.irr.org/nbd-review.html'>New
Bible <B>Dictionary Review</B></A>

... And I would like consider the /*- as stringstart and </B> as stringends?

Thanks

JL

Kor
07-27-2005, 09:25 AM
any character inside a string is considered a substring (except some special characters - in your case it might be your quote character), no matter is a number or whichever. So that in your example,
"1122474436/*-http://www.irr.org/nbd-review.html'>New Bible <B>Dictionary Review</B></A>"
the startstring will be 1 and the endstring will be >. The string must be unwrapped.

hourang
07-27-2005, 03:00 PM
Thank you Hourang!

But... if there is not blank spaces? like this:

1122474436/*-http://www.irr.org/nbd-review.html'>New
Bible <B>Dictionary Review</B></A>

... And I would like consider the /*- as stringstart and </B> as stringends?

Thanks

JL

not sure what you mean about blank spaces as there are a few in that string but here is the code to use the indexes of the strings you specified.


var thestring="1122474436/*-http://www.irr.org/nbd-review.html'>New Bible <B>Dictionary Review</B></A>";
var charlength = 1;
var thestartindex = thestring.indexOf("/*");
var theendindex = thestring.indexOf("</B>");
var stringstart = thestring.substr(thestartindex+2,charlength);
var stringend = thestring.substr(theendindex-charlength,charlength);

alert(stringstart);
alert(stringend);
this alerts the "-" for stringstart and "w" for string end. changing charlength gives you more of the value. if you want the text in between the "/*" and the "</B>" you can put :

var stringinbetween = thestring.substr(thestartindex + 2,thestring.length - (thestring.length-theendindex) - thestartindex - 2);

martin_narg
07-27-2005, 03:23 PM
Also, regular expressions (http://www.devguru.com/Technologies/ecmascript/quickref/regexp.html) can be used as a slightly more advanced method of string manipulation.

m_n

hourang
07-27-2005, 03:32 PM
Also, regular expressions (http://www.devguru.com/Technologies/ecmascript/quickref/regexp.html) can be used as a slightly more advanced method of string manipulation.

m_n

yeah but substr is easier to learn. i hope i made it simple enough so that janlee can learn how this works instead of just copying code and having to get help on here for every little change in the code needed. janlee, if you need help understanding any part of the code, please ask, i can tell you what each step does exactly. :D

JANLEE
07-27-2005, 09:18 PM
Many thanks.

I am very grateful!

JL