JavaScript Equivalent of PHP Explode Function
by Amrit HallanByteswoth.com
Friday, 17th March 2006
$longstring=”Most of the time Amrit is confused — OK, not most of the time”;
$brokenstring=explode(” “, $longstring);
$brokenstring=explode(” “, $longstring);
After the execution of the second command the variable $brokenstring is an array such that,
$brokenstring[0]=”Most”
$brokenstring[1]=”of”
$brokenstring[2]=”the”
$brokenstring[3]=”time”
$brokenstring[4]=”Amrit”
$brokenstring[5]=”is”
$brokenstring[6]=”confused”
$brokenstring[1]=”of”
$brokenstring[2]=”the”
$brokenstring[3]=”time”
$brokenstring[4]=”Amrit”
$brokenstring[5]=”is”
$brokenstring[6]=”confused”
and so on. So how do we do it in JavaScript. In JavaScript there is a split() function that achieves the same objective, although the syntax is a bit different.
var longstring=”Most of the time Amrit is confused — OK, not most of the time”;
var brokenstring=longstring.split(” “);
var brokenstring=longstring.split(” “);
Now the variable brokenstring has all those words.
Options:
Printer Friendly
Email Friend
About The Author:
Amrit Hallan is a freelance web designer. For all web site development and web promotion needs, you can get in touch with him at amrit@bytesworth.com . For further details, visit http://www.bytesworth.com You can subscribe to his newsletter [BYTESWORTH REACHOUT] on Web Designing Tips & Tricks by sending a blank email at bytesworth-subscribe@topica.com.
Amrit Hallan is a freelance web designer. For all web site development and web promotion needs, you can get in touch with him at amrit@bytesworth.com . For further details, visit http://www.bytesworth.com You can subscribe to his newsletter [BYTESWORTH REACHOUT] on Web Designing Tips & Tricks by sending a blank email at bytesworth-subscribe@topica.com.
