Vb.net 将纯文本转换为文本框格式

Vb.net 将纯文本转换为文本框格式,vb.net,Vb.net,我正在搜索将纯文本转换为这种格式的代码 我是说 例如,如果存在纯文本=v6.23b 12全文 所以我想要它把这个文本转换成这个格式 格式 版本6.23内部版本12 就这样。不应在格式中看到“完整”,如何 Dim oldText As String = "v6.23b 12 Full" Dim newText As String = oldText.Replace("v", "version ").Replace("b", " Build").Replace("Full", String.Empt

我正在搜索将纯文本转换为这种格式的代码

我是说

例如,如果存在纯文本=v6.23b 12全文

所以我想要它把这个文本转换成这个格式

格式

版本6.23内部版本12

就这样。不应在格式中看到“完整”,如何

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

请注意,如果字符串中有其他“v”或“b”,则会出现问题。

强迫自己学习正则表达式,因此这似乎是一个很好的练习

我使用这两个网站来了解这些:

以下是我使用正则表达式的版本:

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
导入System.Text.RegularExpressions
公开课表格1
私有子按钮1\u单击(发送者作为对象,e作为事件参数)处理按钮1。单击
Dim版本为String=“v6.23b 12完整”
调试.打印(版本)
'在单词边界的开头找到一个“v”,后面有一个可选空格,
'后接一个或多个数字,后面有一个可选点。带可选点的数字
“之后可以重复一次或多次。
'将该“v”更改为“version”,后面加空格:
version=Regex.Replace(version,“\bv?”(?=[\d+\.?]+),“version”)
调试.打印(版本)
'找到一个或多个数字,后跟一个可选点,该类型的序列可以重复。
'查找后跟可选空格和单词边界上的“b”或“b”的序列类型。
'将“b”改为“Build”,前面加空格:

version=Regex.Replace(version,“(?它工作了,但可能还有其他情况。)如果有相同的文本,它会工作,但我希望它不应该在“12”之后显示任何单词,因为可能有一个单词“full”或“trail”。所以请帮助我,你需要使用你的编程技能。如果你总是只想要前10个字符(或其他任何字符),然后首先对子字符串进行编码。如果您总是想删除“full”,请对其进行编码,如果您总是想删除“trial”,请对其进行编码。好的,我知道我应该做什么了。谢谢您的指导:)