[英]Replace part of String, using regex and vb.net
我的应用程序将 userdata.dll 的路径存储在一个字符串中。
我需要转换这个字符串: C:\\Applications\\User\\userdata.dll
进入这个: C:\\\\Applications\\\\User\\\\userdata.dll
所有\\
都需要复制,与路径有多少\\
无关。
就像是:
Dim defaultPath As String = "C:\Applications\User\userdata.dll"
' Regex
Dim r As Regex = New Regex( ... )
' This is the replacement string
Dim Replacement As String = " ... $1 ... "
' Replace the matched text in the InputText using the replacement pattern
Dim modifiedPath As String = r.Replace(defaultPath,Replacement)
这有什么帮助吗? 我试图遵循这个问题:
但无法找到如何制作这个正则表达式......
您可以使用
Dim pattern As String = "\\"
Dim rgx As New Regex(pattern)
Dim input As String = "C:\Applications\User\userdata.dll"
Dim result As String = rgx.Replace(input, "\\")
Console.WriteLine(result)
如果您的意思是说将任意数量的\\
替换为\\\\
,那么您可以使用
Dim pattern As String = "\\+"
Dim rgx As New Regex(pattern)
Dim input As String = "C:\\\\Applications\User\userdata.dll"
Dim result As String = rgx.Replace(input, "\\")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.