I have a label with text "09-45". How do I get the texts 09 and 45 in 2 separate labels? I need this in a javascript function.
Asked
Active
Viewed 70 times
-2
-
use split function to separate them. – Bojan Kovacevic Apr 09 '13 at 10:29
-
Hi I am new to this. Could you please elaborate? – MusicLovingIndianGirl Apr 09 '13 at 10:29
-
i posted answer below. – Bojan Kovacevic Apr 09 '13 at 10:32
-
I get the result in Chrome..Thanks! – MusicLovingIndianGirl Apr 09 '13 at 10:34
3 Answers
2
for example:
var str = "09-45";
var spl = str.split("-");
var first = spl[0];
var second = spl[1];

Bojan Kovacevic
- 778
- 7
- 19
1
By using .split
?
var string = "string-split";
var arrayPieces = string.split('-');
alert(arrayPieces[1]); // Output: split

Ron van der Heijden
- 14,803
- 7
- 58
- 82
-
It shows this error in IE.."Line: 55 Error: Function expected" – MusicLovingIndianGirl Apr 09 '13 at 10:32
-
1
Use a = myvar.split("-");
to split the string to an array of strings.
Then a[0]
will contain "09" and a[1]
will contain "45";

Aki Suihkonen
- 19,144
- 1
- 36
- 57
-
It shows this error in IE.."Line: 55 Error: Function expected" – MusicLovingIndianGirl Apr 09 '13 at 10:32
-
@Aishvarya: And what do you expect us to do with this information? We don't know your code. – Felix Kling Apr 09 '13 at 10:33
-
@Felix: I wanted a general syntax that's it. Many people who have replied here don't know the code either.. anyway .. I have got the result in Chrome..Thanks. – MusicLovingIndianGirl Apr 09 '13 at 10:35
-