在文本框中查找所有重复的数字字符串 [英] Find all repeating numeric strings within a textbox

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

问题描述

使用Visual Studio 2008,我有一个根据当前日期生成随机字符的代码.当时间变化不够快,或者程序开始出现故障时,我会重复输入数字.每个数字字符串都放置在文本框中,每次生成数字字符串时,都会将其放置在新行中.我需要一个代码片段,它将找到包含包含数字的重复字符串,如下所示:
162763-115235-205.2218

我需要一段代码,以便为每个重复的实例在另一个文本框中显示重复的字符串.

谢谢.

[edit]
只是我的应用程序功能的描述.
用户按下按钮.
数字文本会生成到文本框中.
文本框中的每一行都是一个单独的值.

现在,我需要做的是找到每个重复的值",然后在另一个文本框中说出来.

谢谢.
[/edit]

Using Visual Studio 2008 I have a code that generates random characters depending on the current date. When time is not changing fast enough, or the program begins to malfunction, I have repeating numbers. each numeric string is placed into a textbox and each time the numeric string is produced, it is placed into a new line. I need a code snippet that will find these repeating string which contain a number like so:
162763-115235-205.2218

I need a piece of code that will show the repeated strings in another textbox for each repeated instance.

Thank You.

[edit]
Just a description of what my application does.
User presses button.
numeric text generates into the text box.
each line in the text box is a separate value.

now what I need to do is find each "value" that repeats and say so in another textbox.

thanks.
[/edit]

推荐答案

只需将您生成的所有Strings放入列表中,然后放开
Just put all the Strings you produced into a List and then let loose the power of Enumerable.Distinct(Of TSource)-Methode (IEnumerable(Of TSource))[^].


While taking set differences may also have been an option I tried a different approach from above utilizing LinQ queries:

public static void CountAllDoubles()
{
    // Create a list of String.
    List<String> listOfStrings = new List<String>{ "AAA", "BBB", "CCC", "AAA", "CCC", "AAA", "DDD" };

    var query = listOfStrings.GroupBy(
        element => element,
        (element, elements) => new
        {
            Key = element,
            Count = elements.Count(),
        });

    Console.WriteLine("Counting all occurrences including single ones:");
    foreach (var result in query)
    {
        Console.WriteLine("\tString: {0} Number of occurrences: {1}", result.Key, result.Count);
    }


    Console.WriteLine("\nCounting only multiple occurrences:");
    foreach (var result in query.Where(a => { return a.Count > 1;  }))
    {
        Console.WriteLine("\tString: {0} Number of occurrences: {1}", result.Key, result.Count);
    }
}




[/编辑]


问候,

曼弗雷德

作为旁注,我今天才有机会使用它.




[/Edit]


Regards,

Manfred

As a side note, I just had an opportunity to use this today.


这篇关于在文本框中查找所有重复的数字字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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