我正在使用VB.Net。 我需要删除文本框中的所有重复字符
例如:
myy naaaame isss Johnn
到
my name is John
有人可以帮帮我吗?
答案 0 :(得分:1)
所以即便如此,我知道zilch关于VB.NET和RegEx在20分钟内发现了它:
Sub Main()
Dim input As String = "myy naaaame isss Johnn"
' You need a regex group that matches any char: (.)
' ... and a back reference: \1
' ... and a count more than one: {1,}
Dim rgx As New Regex("(.)\1{1,}")
' use the regex to Replace by the first char of the match group
Dim output As String = rgx.Replace(input, New MatchEvaluator(Function(ByVal m)
Return m.Value.First
End Function))
End Sub