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
  • 37,241
  • 25
  • 195
  • 267
jslearner
  • 21,331
  • 18
  • 37
  • 35

5 Answers5

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

split the string and get part 1

'part1/part2'.split('/')[0]
KooiInc
  • 119,216
  • 31
  • 141
  • 177
2
var tokens = 'part1/part2'.split('/');
alex
  • 479,566
  • 201
  • 878
  • 984
1
var delimeter = '/';

var string = 'part1/part2';

var splitted = string.split(delimeter);

alert(splitted[0]); //alert the part1
Teneff
  • 30,564
  • 13
  • 72
  • 103
1
var result = YourString.split('/');

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

c3p0
  • 35
  • 5