4

Possible Duplicate:
How do I split a string, breaking at a particular character?

I have a string in following format

part1/part2

/ is the delimiter

now I want to get split the string and get part 1. How can I do it?

Cœur
  • 34,719
  • 24
  • 185
  • 251
jslearner
  • 19,701
  • 17
  • 36
  • 35

5 Answers5

14
result = "part1/part2".split('/')
result[0] = "part1"
result[1] = "part2
x10
  • 3,630
  • 1
  • 22
  • 32
4

split the string and get part 1

'part1/part2'.split('/')[0]
KooiInc
  • 112,400
  • 31
  • 139
  • 174
2
var tokens = 'part1/part2'.split('/');
alex
  • 460,746
  • 196
  • 858
  • 974
1
var delimeter = '/';

var string = 'part1/part2';

var splitted = string.split(delimeter);

alert(splitted[0]); //alert the part1
Teneff
  • 26,872
  • 8
  • 62
  • 92
1
var result = YourString.split('/');

For your example result will be an array with 2 entries: "part1" and "part2"

c3p0
  • 35
  • 5