2013-10-30 28 views
0

我有這個字符串「Raw:463 -22 -17 Raw:463 -22 -17Raw:」,但我只想得到「463 -22 -17」等,基本上只是數值。我如何從字符串中提取?順便說一下,第一個數字和第二個數字之間有3個空格,第二個和第三個數字是相同的。但是,第三個和下一個號碼之間沒有空格。這種模式不斷重複。請幫幫我。 在此先感謝 乾杯!如何從vb.net中的字符串提取值?

+1

你能告訴我們一些你的代碼?你可以做一個正則表達式匹配或一系列子字符串和替換。 –

+0

你可以使用sting split function ... – matzone

回答

0

您可以使用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) 
0

試試這個:如果你想獲得的所有值了,你能做到這一點的整數

result

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

從你的樣本數據,你會得到:

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)) 

而且,讓你:

result 2

+0

爲什麼'new String(){「Raw:」}'而不是''Raw:「'? – RBarryYoung

+1

@RBarryYoung - 沒有重載需要一個字符串。 – Enigmativity

+0

對,我忘了.Net'String.Split(..)'版本是如何搞砸的。內置的VB'Split(..)'函數沒有這個問題。 – RBarryYoung