vb.net - Get certain part of string -


so im getting client, computer name , ip. im getting server picks them in textbox multiline. so, im getting message this: name: xxx-pc; ip: xxx.xxx.xxx.xxx ! want take name , ip form, how extract name/ip when lenght different? thanks

this candidate regex.match() using pattern

"^name: (.*?); ip: (.*?)$" 

breakdown:

  • ^ - beginning of string
  • name: - literal string
  • (.*?) - 0 or more characters stored in capture group 1
  • ; ip: - literal string
  • (.*?) - 0 or more characters stored in capture group 2
  • $ - end of string

code sample:

imports system imports system.text.regularexpressions  public module module1     public sub main()         dim data string = "name: xxx-pc; ip: xxx.xxx.xxx.xxx"         dim name string = string.empty         dim ip string = string.empty          dim match = regex.match(data, "^name: (.*?); ip: (.*?)$")         if match.success             name = match.groups(1).value             ip = match.groups(2).value         end if          console.writeline(name)         console.writeline(ip)     end sub end module 

results:

xxx-pc xxx.xxx.xxx.xxx 

fiddle demo


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -