简体   繁体   English

如何从vb.net中的字符串中提取值?

[英]how to extract values from a string in vb.net?

i have this string "Raw: 463 -22 -17Raw: 463 -22 -17Raw:", but i only want to get "463 -22 -17" etc, basically just the numeric value. 我有此字符串“ Raw:463 -22 -17Raw:463 -22 -17Raw:”,但我只想获取“ 463 -22 -17”等,基本上只是数值。 how do i do extract that from a string? 我如何从字符串中提取出来? by the way, there are 3 spaces between the first number and second number, same thing for the second and third number. 顺便说一句,第一个数字和第二个数字之间有3个空格,第二个和第三个数字相同。 however, there is no space between the third and next number. 但是,第三个数字和下一个数字之间没有空格。 this pattern keeps repeating. 这种模式不断重复。 please help me. 请帮我。 thanks in advance cheers! 在此先感谢您的欢呼!

You can use REPLACE. 您可以使用REPLACE。

     Dim x As String = "Raw: 463 -22 -17Raw: 463 -22 -17Raw:"
     x = Replace(x, "Raw: ", " ") '<-I added an empty space as replacement, but you can use whatever you like.
     MsgBox(x)

Try this: 尝试这个:

Dim values = text.Split( _
    New String() { "Raw:" }, _
    StringSplitOptions.RemoveEmptyEntries)

From your sample data you get this: 从样本数据中您可以得到:

结果

If you want to get all the values out as integers you could do this: 如果要获取所有值作为整数,可以执行以下操作:

Dim values = _
    From numbers in text.Split( _
        New String() { "Raw:" }, _
        StringSplitOptions.RemoveEmptyEntries) _
    Select numbers.Split( _
        New Char() { " "c }, _
        StringSplitOptions.RemoveEmptyEntries) _
            .Select(Function (x) Integer.Parse(x))

And that gives you: 那给你:

结果2

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

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