how to split with ( ' \n ', ' ', ',' , ';' ) in javascript

Posted by Abhi_patil under JavaScript on 2/20/2009 | Views : 21640 | Status : [Member] | Replies : 2
i want to split string with comma,space,newline,semicolon;

as like we can do in c# i.e

char[] arr={ ' \n ', ' ', ',' ,' ;' };
string[] str=str1.split(arr);

how i can do this in javascript..
please.
thank you.




Responses

Posted by: Neeks on: 2/23/2009 [Member] Bronze

Up
0
Down
<script language="javascript" type="text/javascript">
function fnSplit(strVal)
{

var data = "; , \n";
strVal = strVal.replace(";", "~"); //Here we are replacing the necessary characters with the '~' sign
alert(strVal);
strVal = strVal.replace(",", "~");//Here we are replacing the necessary characters with the '~' sign
alert(strVal);
strVal = strVal.replace("\n", "~");//Here we are replacing the necessary characters with the '~' sign
alert(strVal);
var splitArr = strVal.split("~");
var intCount = 0;
while(intCount < splitArr.length)
{
alert(splitArr[intCount]);
intCount += 1;
}
}
</script>

Abhi_patil, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: SqlDeveloper on: 9/25/2009 [Member] Starter

Up
0
Down
Please refer to article http://www.kodyaz.com/articles/javascript-string-split-function-example.aspx for more text splitting with js.

Abhi_patil, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response