PDA

View Full Version : split a string by 3 condition .......pls help



pankaj.ghadge
12-23-2008, 01:15 PM
hello,

i want to split a string by 3 condition.
1)<​f​o​n​t​ ​s​t​y​l​e​=​"​c​o​l​o​r​:​ ​b​l​u​e​;​ ​b​a​c​k​g​r​o​u​n​d​-​c​o​l​o​r​: yellow;">
2)</font>
3)rest of the string.

suppose string is as bellow ........(string is created dynamically so len is not specific)
<​f​o​n​t​ ​s​t​y​l​e​=​"​c​o​l​o​r​:​ ​b​l​u​e​;​ ​b​a​c​k​g​r​o​u​n​d​-​c​o​l​o​r​: yellow;"> ​h​i </font> hihisadsadasdfsdffasdf
<f​o​n​t​ ​s​t​y​l​e​=​"​c​o​l​o​r​:​ ​b​l​u​e​;​ ​b​a​c​k​g​r​o​u​n​d​-​c​o​l​o​r​: yellow;"> hi</font>

​​output
suppose a is array :

a[0]=><​f​o​n​t​ ​s​t​y​l​e​=​"​c​o​l​o​r​:​ ​b​l​u​e​;​ ​b​a​c​k​g​r​o​u​n​d​-​c​o​l​o​r​: yellow;">
a[1]=>h​i
a[2]=></font>
a[3]=>hihisadsadasdfsdffasdf
a[4]=><f​o​n​t​ ​s​t​y​l​e​=​"​c​o​l​o​r​:​ ​b​l​u​e​;​ ​b​a​c​k​g​r​o​u​n​d​-​c​o​l​o​r​: yellow;">
a[5]=>hi
a[6]=></font>


<​f​o​n​t​ ​s​t​y​l​e​=​"​c​o​l​o​r​:​ ​b​l​u​e​;​ ​b​a​c​k​g​r​o​u​n​d​-​c​o​l​o​r​: yellow;"> & </font> will remain same only the string will change from the whole string.

please tell me how to split ..........................................

Nile
12-23-2008, 04:03 PM
Now, I don't extremely get how you want to split the string, but take a look at the split() function:
http://www.w3schools.com/jsref/jsref_split.asp

And regular expressions:

http://www.javascriptkit.com/jsref/regexp.shtml