在VB.net中解压缩模式(decompress a pattern in VB.net)

编程入门 行业动态 更新时间:2024-10-23 15:29:11
在VB.net中解压缩模式(decompress a pattern in VB.net)

我仍然是dotNET的新手,我一直在搜索和搜索,并试图弄明白这一点。

我有一个字符串模式,如下所示:

3(a)-bab-4(c)-aab-7(d)-abab <---- pattern总是不同的,最多可以有50或60个字符

我需要的是:

aaababccccaabdddddddabab

有人可以帮我解决这个问题吗?

I am still very new to dotNET, and I have searched and searched, and racked my brain trying to figure this out.

I have a pattern as a string which looks like this :

3(a)-bab-4(c)-aab-7(d)-abab                       <---- pattern is always different and can be up to 50 or 60 characters

What I need is:

aaababccccaabdddddddabab

Can someone please help me figure this out?

最满意答案

这是一个可以使用您给出的示例的函数。 它使用String.Split和String.Replace来解析您的数据。

Module Module1 Sub Main() Dim testValue As String = "3(a)-bab-4(c)-aab-7(d)-abab" Console.WriteLine(testValue) Console.WriteLine(ParseData(testValue)) Console.ReadLine() End Sub Public Function ParseData(value As String) As String Dim temp As String = "" Dim result As String = "" Dim splitChar As Char() = {"-"c} Dim split() As String = value.Split(splitChar, StringSplitOptions.RemoveEmptyEntries) For Each section In split If (IsNumeric(section(0))) Then 'Check to see if section starts with a number Dim tmpvalue1() As String = section.Split(New Char() {"("c}) 'Check if section contains a paren If tmpvalue1.Length > 0 Then 'If so then replace them and strip out the number to get to the repeating characters Dim validChar As String = section.Replace("(", "").Replace(")", "").Replace(tmpvalue1(0), "") Dim count As Integer If Integer.TryParse(tmpvalue1(0), count) Then temp = validChar For x = 0 To count - 2 temp += validChar Next End If End If result += temp Else result += section End If Next Return result End Function End Module

结果:

在此处输入图像描述

Here is a function that will work with the example that you gave. It is using String.Split and String.Replace to parse out your Data.

Module Module1 Sub Main() Dim testValue As String = "3(a)-bab-4(c)-aab-7(d)-abab" Console.WriteLine(testValue) Console.WriteLine(ParseData(testValue)) Console.ReadLine() End Sub Public Function ParseData(value As String) As String Dim temp As String = "" Dim result As String = "" Dim splitChar As Char() = {"-"c} Dim split() As String = value.Split(splitChar, StringSplitOptions.RemoveEmptyEntries) For Each section In split If (IsNumeric(section(0))) Then 'Check to see if section starts with a number Dim tmpvalue1() As String = section.Split(New Char() {"("c}) 'Check if section contains a paren If tmpvalue1.Length > 0 Then 'If so then replace them and strip out the number to get to the repeating characters Dim validChar As String = section.Replace("(", "").Replace(")", "").Replace(tmpvalue1(0), "") Dim count As Integer If Integer.TryParse(tmpvalue1(0), count) Then temp = validChar For x = 0 To count - 2 temp += validChar Next End If End If result += temp Else result += section End If Next Return result End Function End Module

Result:

enter image description here

更多推荐

本文发布于:2023-07-14 20:35:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1107241.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:解压缩   模式   net   VB   decompress

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!