Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. String manipulation

String manipulation

Scheduled Pinned Locked Moved C#
tutorialcode-review
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    steve_rm
    wrote on last edited by
    #1

    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,

    G N L 3 Replies Last reply
    0
    • S steve_rm

      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,

      G Offline
      G Offline
      Giorgi Dalakishvili
      wrote on last edited by
      #2

      You can use extract username using Substring method of string class.

      Giorgi Dalakishvili #region signature my articles #endregion

      1 Reply Last reply
      0
      • S steve_rm

        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,

        N Offline
        N Offline
        Nouman Bhatti
        wrote on last edited by
        #3

        split your string on : and @ it will return u a string array... and on 2nd index u will find the username

        1 Reply Last reply
        0
        • S steve_rm

          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,

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          <[^:]+:(?<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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups