-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,817
  • 8
  • 33
  • 65

3 Answers3

2

for example:

var str = "09-45";
var spl = str.split("-");
var first = spl[0];
var second = spl[1];
Bojan Kovacevic
  • 738
  • 7
  • 18
1

By using .split?

var string = "string-split";
var arrayPieces = string.split('-');
alert(arrayPieces[1]); // Output: split
Ron van der Heijden
  • 14,340
  • 7
  • 55
  • 81
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
  • 18,135
  • 1
  • 34
  • 55