|
-
January 16th, 2012, 09:39 PM
#1
Split string
hello,
does anyone know how to split a string?
so far I have the following:
Code:
var string = "Hello my name is - Bob";
alert( sring.split('-', 2) );
however, I am not 100% sure if i am doing it correct.
I am trying to get the bob part of the string only.
but it displays Hello my name is , bob
Does anyone know what I am doing wrong?
-
January 18th, 2012, 11:59 AM
#2
Re: Split string
You're splitting properly. Remember that it returns an array.
This is very, very basic JavaScript. I suggest you go to W3Schools' JavaScript section and brush up a bit.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
January 27th, 2012, 04:54 AM
#3
Re: Split string
Here is the code to split a string in javascript..Hope it will work for you
string.split(separator, limit)
An example for your help goes like this :
<script type="text/javascript">
var str="How are you doing today?";
document.write(str.split() + "<br />");
document.write(str.split(" ") + "<br />");
document.write(str.split("") + "<br />");
document.write(str.split(" ",3));
</script>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|