在 vb.net 中比较字符串和修剪

发布于 2024-08-28 11:28:50 字数 415 浏览 6 评论 0原文

我有一个来自另一个文件的字符串。该字符串的最大长度为 102 位。我需要将字符串与一对数字进行比较,然后从该字符串中删除这些数字。

例如 - 6125223659587412563265...直到 102 个

与该字符串比较的数字

- 第一组 - 61 个

新字符串 = 25223659587412563265

第二组 - 36 个

新字符串 = 252259587412563265

等等。该组数字最多应有 51 对 = 102,这将给出 string = "" 的最终结果 我怎样才能在循环中实现这一目标?


这不是答案,这是编辑问题。我不知道为什么,但编辑按钮消失了,所以我必须在这里编辑问题。 该字符串中不会出现重复项。最后,当比较完成后,我想看看成对留下了哪些数字。

I have this string that shall come in from another file. The string has maximum length of 102 digits. I need to compare the string with numbers in a pair and delete those from that string.

e.g - 6125223659587412563265... till 102

numbers that compare with this string-

first set - 61

new string = 25223659587412563265

second set - 36

new string = 252259587412563265

and so on. the set of numbers shall go to maximum of 51 pairs = 102, which shall give an end result of string = ""
How can i achieve this in a loop?


this is not answer, this is editing the question. i dont know why but the edit button just vaniashed so i have to edit question here.
No duplicates will ever be in this string. and in the end when compares are done, i want to see what numbers are left in pairs.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

青衫儰鉨ミ守葔 2024-09-04 11:28:50
Dim input As String = "6125223659587412563265"
Dim targets As String() = {"61", "36"}

For Each target As String In targets
    input = input.Replace(target, "")
Next
Debug.Assert(input = "252259587412563265")
Dim input As String = "6125223659587412563265"
Dim targets As String() = {"61", "36"}

For Each target As String In targets
    input = input.Replace(target, "")
Next
Debug.Assert(input = "252259587412563265")
北渚 2024-09-04 11:28:50

这是一个简单的解决方案。您需要将您的对添加到 List(Of String) 中,并初始化要更改的字符串的输入。

Dim pairs As New List(Of String)()
Dim input As String = String.Empty
For Each pair As String In pairs
    input = input.Replace(pair, String.Empty)
Next

Here is a simple solution. You will need to add your pairs to the List(Of String) and also initialize input to the string you want to alter.

Dim pairs As New List(Of String)()
Dim input As String = String.Empty
For Each pair As String In pairs
    input = input.Replace(pair, String.Empty)
Next
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文