2015-07-01 82 views
0

我尋找的是純文本轉換爲這種格式轉換純文本到文本框格式

我的意思是

舉例來說,如果有一個純文本代碼= v6.23b 12全

,所以我想將其轉換這個文本格式

格式

版本6.23構建12

就是這樣。不應在格式

回答

0

可以看到單詞「」如何

Dim oldText As String = "v6.23b 12 Full" 
Dim newText As String = oldText.Replace("v", "version ").Replace("b", " Build").Replace("Full", String.Empty) 

請注意,您有問題,如果有其他的「V」 S或字符串中的「B」。

+0

它的工作,但也可能有其他情況..它會如果有相同的文本,但我希望它不應該顯示任何單詞後「12」,因爲可能有一個詞「全」或「足跡」。所以PLZ幫助我 – Aditya

+0

然後,你需要把你的編程技能使用。如果你總是隻想要前10個字符(或其他),那麼首先編寫一個'SubString'。如果你總是想刪除'完整',那麼代碼,如果你總是想刪除'試用',編碼。 –

+0

好吧,我知道我應該做什麼..感謝您的指導:) – Aditya

0

我迫使自己學習正則表達式,所以這似乎是一個很好的鍛鍊......

我使用這兩個網站推測這些了:

http://www.regular-expressions.info/tutorial.html

https://msdn.microsoft.com/en-us/library/az24scfc(v=vs.110).aspx

這裏的我的版本使用正則表達式:

Imports System.Text.RegularExpressions 
Public Class Form1 

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click 
     Dim version As String = "v6.23b 12 Full" 
     Debug.Print(version) 

     ' Find a "v" at the beginning of a word boundary, with an optional space afterwards, 
     ' that is followed by one or more digits with an optional dot after them. Those digits with an optional dot 
     ' after them can repeat one or more times. 
     ' Change that "v" to "version" with a space afterwards: 
     version = Regex.Replace(version, "\bv ?(?=[\d+\.?]+)", "version ") 
     Debug.Print(version) 

     ' Find one or more or digits followed by an optional dot, that type of sequence can repeat. 
     ' Find that type of sequence followed by an optional space and a "b" or "B" on a word boundary. 
     ' Change the "b" to "Build" preceded by a space: 
     version = Regex.Replace(version, "(?<=[\d+\.?]+) ?b|B\b", " Build") ' Change "b" to "Build" 
     Debug.Print(version) 

     ' Using a case-insensitive search, replace a whole word of "FULL" or "TRIAL" with a blank string: 
     version = Regex.Replace(version, "(?i)\b ?full|trial\b", "") 
     Debug.Print(version) 
    End Sub 

End Class