110,545
社区成员
发帖
与我相关
我的任务
分享
using System;
class Program
{
static void Main(string[] args)
{
Console.WriteLine(CharRepeatCheck("a;b;v;n;mm;tt;yy;b;y;ca;a") ? "有重复的字符" : "没有重复字符");
}
static bool CharRepeatCheck(string value)
{
char[] values = value.Replace(";","").ToCharArray();
int a=values.Distinct().Count();
HashSet<string> hs = new HashSet<string>();
foreach (char entity in values)
{
if (!hs.Add(entity.ToString()))
{
return true;
}
}
return false;
}
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine( StringRepeatCheck("a;b;v;n;mm;tt;yy;b;y;ca;a")?"有重复的":"没有重复");
}
static bool StringRepeatCheck(string value)
{
string[] values = value.Split(';');
HashSet<string> hs = new HashSet<string>();
foreach (string entity in values)
{
if (!hs.Add(entity.ToString()))
{
return true;
}
}
return false;
}
}
string test = "a;b;v;n;mm;tt;yy;b;y;ca;a";
Regex reg = new Regex(@"(?s)(?<=^|;)([^;]+)(?=;).*?(?<=;)\1(?=;|$)");
if (reg.IsMatch(yourStr))
{
richTextBox2.Text = "有重复值!";
}
else
{
richTextBox2.Text = "没有重复值!";
}
string[] ary = { "a","b","c","a"};
Dictionary<string, string> dict = new Dictionary<string, string>();
try
{
foreach (var s in ary)
{
dict.Add(s, null);
}
}
catch (Exception e)
{
Console.WriteLine("存在相同的值");
}
string source = "a;b;v;n;mm;tt;yy;b;y;ca;a";
System.Text.RegularExpressions.Regex re = new System.Text.RegularExpressions.Regex("\\w+");
List<string> Arrlist = new List<string>();
System.Text.RegularExpressions.MatchCollection mc = re.Matches(source);
foreach (Text.RegularExpressions.Match m in mc) {
//Console.WriteLine(m.Value)
if (!Arrlist.Contains(m.ToString)) {
Arrlist.Add(m.ToString);
Console.WriteLine(m.ToString);
}
}
Console.ReadLine();