tags:

views:

6213

answers:

3

I need to break apart a string that always looks like this: something -- something_else. I need to put "something_else" in another input field. Currently, this string example is being added to an HTML table row on the fly like this:

tRow.append($('<td>').text($('[id$=txtEntry2]').val()));

I figure "split" is the way to go but there is very little documentation that I can find yet.

+2  A: 

look here

"something -- something_else".split(" -- ") 
vittore
+3  A: 

Are you talking about the basic javascript split function? If so, here's some documentation that should help you out:

http://www.w3schools.com/jsref/jsref_split.asp

Basically, you just do this:

var array = myString.split(' -- ')

Then your two values are stored in the array - you can get the values like this:

var firstValue = array[0];
var secondValue = array[1];
Charles Boyung
+4  A: 

Documentation can be found e.g. at w3schools.com. If you use .split() on a string, then you get an array back with the substrings:

var str = 'something -- something_else';
var substr = str.split(' -- ');
// substr[0] contains "something"
// substr[1] contains "something_else"

If this value is in some field you could also do:

tRow.append($('<td>').text($('[id$=txtEntry2]').val().split(' -- ')[0])));
Felix Kling