substring - Javascript - cutting out part of a string -


hello everyone,

i'm trying find best way cut out specific parts of below input string. i'm using white space (' ') separator. i'm unable cut out required parts , assign them respective variables.

var input = "/w user1 message"  var user = input.substring(2, input.indexof(' '));??  var message = ??? 

expected result:

user = "user1" message = "message" 

it works when empty spaces replaced coma or other separator.

is there specific reason why iit's not working spaces?

thanks in advance, alex

i recommend using split, creates array , can access array index

http://jsfiddle.net/pjh28/

var input = "/w user1 message"  var inputparts = input.split(' '); var message = inputparts[2]; console.log(message); 

Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -