-2

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.

MusicLovingIndianGirl
  • 5,909
  • 9
  • 34
  • 65

3 Answers3

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
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