简体   繁体   English

获取字符串的特定部分

[英]Get certain part of a string

I am getting a little piece of code from a client to a server, which looks like this:我从客户端到服务器获取一小段代码,如下所示:

"NAME: " & My.Computer.Name & "; IP: " & GetExternalIp()

This Code is beeing recieved by the server in a textbox(txt.Chat) with multiline.. So I'm actually kind of re-asking this, because the question I asked wasn't really understandable.这段代码被服务器在一个多行的文本框(txt.Chat)中收到。所以我实际上是在重新问这个问题,因为我问的问题并不是真的可以理解。 Some user answered this:有用户这样回答:

Dim stringFromClient As String = "Name: xxx-PC; IP: xxx.xxx.xxx.xxx" 
Dim values() As String = stringFromClient.Split(";")
Dim name As String = values(0).Split(":").Last.Trim
Dim IP As String = values(1).Split(":").Last.Trim
Debug.Print("name = " & name)
Debug.Print("IP = " & IP)

I tried this out, but the problem was that I was getting this output: "Name: xxx-PC; IP: xxx.xxx.xxx.xxx" which isn't actually what i want.. i dont know how to set the "stringfromClient" string correctly.我试过了,但问题是我得到了这个输出:“名称:xxx-PC;IP:xxx.xxx.xxx.xxx”这实际上不是我想要的......我不知道如何设置“stringfromClient”字符串正确。

To set the string do this:要设置字符串,请执行以下操作:

Dim stringFromSomewhere As String = "NAME: " & My.Computer.Name & "; IP: " & GetExternalIp()

To extract the values do this:要提取值,请执行以下操作:

Dim values() As String = stringFromSomewhere .Split(";")
Dim name As String = values(0).Split(":").Last.Trim
Dim IP As String = values(1).Split(":").Last.Trim
Debug.Print("name = " & name)
Debug.Print("IP = " & IP)

"name" and "IP" will contain the name and IP data from the original string "name" 和 "IP" 将包含来自原始字符串的名称和 IP 数据

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM