我对 dotNET 还是很陌生,我搜索了又搜索,绞尽脑汁想弄明白。
我有一个字符串模式,如下所示:
3(a)-bab-4(c)-aab-7(d)-abab <---- 模式总是不同的,最多可以有 50 或 60 个字符
我需要的是:
aaababccccaabddddddabab
谁能帮我解决这个问题?
最佳答案
好吧,它看起来像一个 RLE,用 '-' 分割你的字符串,然后检查是否包含 '(',如果是,取数字,提取文本并循环重复
Dim sb As New StringBuilder()
Dim parts As String() = inputString.Split("-"C)
For Each part As String In parts
Dim indexOfPar As Integer = part.IndexOf("(")
If indexOfPar = -1 Then
sb.Append(part)
Else
Dim repeat As Integer = Integer.Parse(part.Substring(0, indexOfPar))
Dim toRepeat As String = part.Substring(indexOfPar, part.Length - (indexOfPar - 2))
'-2 to remove ()
For buc As Integer = 0 To repeat - 1
sb.Append(toRepeat)
Next
End If
Next
Return sb.ToString()
关于.net - 在 VB.net 中解压一个模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23051166/