如何在Visual Basic NET中找到重复的字符链 [英] How to find a repeated chain of chars in visual basic NET

查看:100
本文介绍了如何在Visual Basic NET中找到重复的字符链的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在RichTextBox中有这段文字:



RichTextBox1.Text = ABCDEF TEST12 ABCDEF



如何获得重复的字符串值ABCDEF?



编辑:要成为更具体地说,我需要一个重复查找器。此图片应说明该计划:图片



我的尝试:



我不知道如何解决这个问题。

I have this piece of text in a RichTextBox:

RichTextBox1.Text = "ABCDEFTEST12ABCDEF"

How can I get the repeated string value "ABCDEF"?

edit: To be more specific, I need a "duplicate finder". This image should illustrate the plan: Image

What I have tried:

I have no idea how to resolve this issue.

推荐答案

答案在于你的问题!



   如何获得重复的字符串值ABCDEF?



我想你是什么真的意思是如何在一堆文本中检测到重复的



第一步是打破将文本输入到一组单词中。 然后,检查集合中的重复条目,可能是通过计算每个单词的出现次数。 不止一次出现的单词就是你的副本。



正如你所看到的,我已经将你的复杂问题分解为两个不太复杂的问题。 你现在的工作就是攻击这些问题并将其分解成更简单的问题。 这被称为逐步细化并且是软件工程的核心 - 您将一个相当抽象和复杂的任务分解为一系列简单且定义明确(因此可编程)的任务。



可能有助于实现目标的一些事情是 String.Split()方法 [ ^ ]和 C#Dictionary [ ^ ]类,您可以使用它来计算您发现的每个单词的出现次数。



/ ravi
The answer lies in your question!

  How can I get the repeated string value "ABCDEF"?

I think what you really meant was "how do I detect a repeated word in a bunch of text?"

The first step would be to break up the input text into a collection of words.  Then, check for duplicate entries in the collection, perhaps by counting the occurences of each word.  Words that occur more than once are your duplicates.

As you can see, I've broken your complex problem into two somewhat less complex problems.  Your job now is to attack each of these problems and break them up into even simpler problems.  This is called stepwise refinement and is at the core of software engineering - you break up a fairly abstract and complex task into a collection of simple and very well defined (and therefore programmable) tasks.

Some things that may help you achieve your goal are the String.Split() method[^] and the C# Dictionary[^] class which you can use to count occurences of each word you've discovered.

/ravi

Dim str() As String = {}
str = Split(RichTextBox1.Text, " ")
Dim str2 As String = ""
Dim str3() As String = {}
Dim duplicate_names As String = ""
Dim i As Integer = 1
For Each name As String In str
    str3 = Split(str2, " ")
    For Each name2 As String In str3
        If name = name2 Then
            If Not duplicate_names.Contains(name) Then
                duplicate_names += name & vbNewLine
                i += 1
            End If
        End If
    Next
    str2 += name & " "
Next
MsgBox(duplicate_names)


这篇关于如何在Visual Basic NET中找到重复的字符链的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆