String manipulation
-
Hello, I have a string "sip:username@10.10.10.10:5060" I would like just to get the "username", and nothing else.
string callStatus = "<sip:username@10.10.10.10:5060>"; string usernameAndIP = callStatus.Remove(0, 5); string[] username = usernameAndIP.Split('@'); this.lblCallStatus.Text = username[0].ToString();
I am using this code above. But and just Interested if there is a better more efficient way to do this. Just looking to improve my code if that is possible, and also will this work for every situation that could arise. For example if the port number hasn't been included. Many thanks, -
Hello, I have a string "sip:username@10.10.10.10:5060" I would like just to get the "username", and nothing else.
string callStatus = "<sip:username@10.10.10.10:5060>"; string usernameAndIP = callStatus.Remove(0, 5); string[] username = usernameAndIP.Split('@'); this.lblCallStatus.Text = username[0].ToString();
I am using this code above. But and just Interested if there is a better more efficient way to do this. Just looking to improve my code if that is possible, and also will this work for every situation that could arise. For example if the port number hasn't been included. Many thanks,You can use extract username using Substring method of string class.
Giorgi Dalakishvili #region signature my articles #endregion
-
Hello, I have a string "sip:username@10.10.10.10:5060" I would like just to get the "username", and nothing else.
string callStatus = "<sip:username@10.10.10.10:5060>"; string usernameAndIP = callStatus.Remove(0, 5); string[] username = usernameAndIP.Split('@'); this.lblCallStatus.Text = username[0].ToString();
I am using this code above. But and just Interested if there is a better more efficient way to do this. Just looking to improve my code if that is possible, and also will this work for every situation that could arise. For example if the port number hasn't been included. Many thanks,split your string on : and @ it will return u a string array... and on 2nd index u will find the username
-
Hello, I have a string "sip:username@10.10.10.10:5060" I would like just to get the "username", and nothing else.
string callStatus = "<sip:username@10.10.10.10:5060>"; string usernameAndIP = callStatus.Remove(0, 5); string[] username = usernameAndIP.Split('@'); this.lblCallStatus.Text = username[0].ToString();
I am using this code above. But and just Interested if there is a better more efficient way to do this. Just looking to improve my code if that is possible, and also will this work for every situation that could arise. For example if the port number hasn't been included. Many thanks,<[^:]+:(?<username>[^@]+)@(?<ip>[^:]+)(:(?<port>\d+))?>
This regular expression should work for most cases, it will include the username, ip and port (if given) in the named groups "username", "ip" and "port" /edit: why does this board include smilies in code and pre tags? Annoying! Just imagine the :( smiliey being ": (" (without space) regards