I can have one of the following strings:
var username = "i:0#.f|myprovider|domain\\myuser"
var username2 = "myprovider|domain\\myuser"
var username3 = "myuser"
I always want only the myuser
part of the string!
I tried the following in JS
var n = username.lastIndexOf('|');
var domainandusername = username.substring(n + 1);
var m = domainandusername.lastIndexOf('"\\"');
var username = domainandusername.substring(m + 1);
I have tried it within a simple page with JS and it seems to work. But is this a good way to solve this? I mean is it a good practice even to do this for string username2
and username3
where I know that they, for example, do not have a |
and \\
?
username
and then avar username
? – Simon Forsberg♦ Sep 13 at 12:23var username
. The other usernamex are possible variants which must be also processable. – STORM Sep 13 at 12:25