I have a string, for example testserver\sho007, how do I use jQuery to return only sho007?
4 Answers
You can do it simply with javascript
var my_string="testserver\sho007";
var left_side=my_string.split("\\")[0];
var right_side=my_string.split("\\")[1];
edited to add the double slash as Eric mentioned
2 Comments
Eric Wilson
Noticing how markdown is confused by "\", I'm curious if JavaScript would understand it, or if it should be
my_string.split("\\")[1]?Adhip Gupta
Yes, you need the two slashes to make it work even in the assignment. In this case even the assignment will ignore the slash.
Use Regular Expressions if you are sure that the text you want is going to be after the slash.
1 Comment
Eric Wilson
Or maybe just
string.split('\')?