.net - 在 VB.net 中解压一个模式

标签 .net vb.net

我对 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/

相关文章:

.net - Right$(string, 3) 的含义

c# - 命名空间的访问修饰符

asp.net - 为什么 Label Width 在 ChangePassword 控件中不起作用?网站

excel - 如何在没有 'Out of Memory' 异常的情况下将大型 DataGridView 导出到 Excel?

.net - 使用 AutoReset = False 时,计时器在停止后仍在滴答作响

c# - ClickOnce 应用程序抛出错误 "..requires assembly MySql.Data Version 6.5.4.0 be installed in the Global Assembly Cache (GAC) first."

.net - 比较对象时的 Equals 与 GetHashCode

c# - 获得用户文化,而不是线程文化

.net - Cassandra .Net 驱动程序和 CQL 驱动程序(2012 年 8 月)

c# - 转换具有句点而不是逗号的 float ?