How to use split?
Documentation can be found e.g. at MDN. Note that .split()
is not a jQuery method, but a native string method.
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])));
If it is the basic JavaScript split function, look at documentation, JavaScript split() Method.
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];
Look in JavaScript split() Method
- Mozilla Developer Network
- W3Schools
Usage:
"something -- something_else".split(" -- ")