C# 比较两个字符串数组
我必须比较这两个字符串,但我不知道如何比较。我尝试了我在网上找到的所有东西,但没有任何效果C# 比较两个字符串数组,c#,arrays,string,compare,equals,C#,Arrays,String,Compare,Equals,我必须比较这两个字符串,但我不知道如何比较。我尝试了我在网上找到的所有东西,但没有任何效果 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Aufgabe_3_2 { class Program { static void Main(string[] args)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Aufgabe_3_2
{
class Program
{
static void Main(string[] args)
{
string[,] zeichenSatz = new string[,] { {" ","0000","0001","0010","0011","0100","0101","0110","0111","1000","1001","1010","1011","1100","1101","1110","1111"}, //creates a string array
{ "0010","SP","!","\"","#","$","%","&","'","(",")","*","+",",","-",".","/"},
{ "0011","0","1","2","3","4","5","6","7","8","9",":",";","<","=",">","?"},
{ "0100","@","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O"},
{ "0101","P","Q","R","S","T","U","V","W","X","Y","Z","[","\\","]","^","_"},
{ "0110","`","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o"},
{ "0111","p","q","r","s","t","u","v","w","x","y","z","{","|","}","~",""},
{ "1010","NBSP","¡","¢","£","¤","¥","¦","§","¨","©","ª","«","¬","SHY","®","¯"},
{ "1011","°","±","²","³","´","µ","¶","·","¸","¹","º","»","¼","½","¾","¿"},
{ "1100","À","Á","Â","Ã","Ä","Å","Æ","Ç","È","É","Ê","Ë","Ì","Í","Î","Ï"},
{ "1101","Ð","Ñ","Ò","Ó","Ô","Õ","Ö","×","Ø","Ù","Ú","Û","Ü","Ý","Þ","ß"},
{ "1110","à","á","â","ã","ä","å","æ","ç","è","é","ê","ë","ì","í","î","ï"},
{ "1111","ð","ñ","ò","ó","ô","õ","ö","÷","ø","ù","ú","û","ü","ý","þ","ÿ"}};
Console.WriteLine("Bitte geben sie ihren Text ein: "); //request a input from user
string strText = Console.ReadLine();
string[] strEingabe; //makes other stuff
strEingabe = strText.Split(default(string[]), StringSplitOptions.RemoveEmptyEntries);
string[] tempArray = new string[strText.Length];
Console.WriteLine(strEingabe);
Console.WriteLine(strText);
Console.WriteLine(strText.Length);
Console.Write("0100||");
for (int h = 0; h < strText.Length; h++)
{
for (int i = 0; i < zeichenSatz.GetLength(0); i++)
{
for (int j = 0; j < zeichenSatz.GetLength(1); j++)
{
if (strText[h].Equals(zeichenSatz[i, j]) == true)
{
Console.WriteLine("{0} , {1}", zeichenSatz[i, 0], zeichenSatz[0, j]);
Console.WriteLine(zeichenSatz[0, j]);
Console.WriteLine(" ");
}
}
}
}
Console.WriteLine("0000");
Console.ReadLine();
}
}
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
名称空间Aufgabe_3_2
{
班级计划
{
静态void Main(字符串[]参数)
{
string[,]zeichenSatz=新字符串[,]{-“,”0000“,”0001“,”0010“,”0011“,”0100“,”0101“,”0111“,”1000“,”1001“,”1010“,”1011“,”1100“,”1101“,”1110“,//创建字符串数组
{“0010”、“SP”、“!”、“\”、“#”、“$”、“%”、“&”、“'、”(“、”、“*”、“+”、“、”、“、”、“-”、“/”},
{ "0011","0","1","2","3","4","5","6","7","8","9",":",";","","?"},
{“0100”、“A”、“B”、“C”、“D”、“E”、“F”、“G”、“H”、“I”、“J”、“K”、“L”、“M”、“N”、“O”},
{“0101”、“P”、“Q”、“R”、“S”、“T”、“U”、“V”、“W”、“X”、“Y”、“Z”、“[”、“\\”、“]”、“^”、“\\”},
{“0110”、“a”、“b”、“c”、“d”、“e”、“f”、“g”、“h”、“i”、“j”、“k”、“l”、“m”、“n”、“o”},
{“0111”,“p”,“q”,“r”,“s”,“t”,“u”,“v”,“w”,“x”,“y”,“z”,“{”,“|”,“}”,“~”,“},
{“1010”、“NBSP”、“…”、“、、”、“·、”、“?、”、“§、”、“、”、”、”、”、“-、”、“、”、“、”、“、”、“、”、”、“},
{ "1011","°","±","²","³","´","µ","¶","·","¸","¹","º","»","¼","½","¾","¿"},
{ "1100","À","Á","Â","Ã","Ä","Å","Æ","Ç","È","É","Ê","Ë","Ì","Í","Î","Ï"},
{ "1101","Ð","Ñ","Ò","Ó","Ô","Õ","Ö","×","Ø","Ù","Ú","Û","Ü","Ý","Þ","ß"},
{ "1110","à","á","â","ã","ä","å","æ","ç","è","é","ê","ë","ì","í","î","ï"},
{ "1111","ð","ñ","ò","ó","ô","õ","ö","÷","ø","ù","ú","û","ü","ý","þ","ÿ"}};
Console.WriteLine(“BITE geben sie ihren Text ein:”;//请求用户输入
字符串strText=Console.ReadLine();
string[]strengabe;//生成其他内容
strengabe=strText.Split(默认值(字符串[]),StringSplitOptions.RemoveEmptyEntries);
string[]tempArray=新字符串[strText.Length];
控制台写入线(strEingabe);
控制台写入线(strText);
Console.WriteLine(strText.Length);
控制台。写入(“0100 | |”);
for(int h=0;h
我们对IEnumerable进行了扩展
在我们的例子中,我们想知道集合A中的所有项目是否都在集合B中,不必按相同的顺序排列,我不知道这是否是您想要的:
public static bool ContentEquals<T>(this IEnumerable<T> enumerable, IEnumerable<T> other)
{
if (Equals(enumerable, other))
{
return true;
}
if (enumerable == null || other == null)
{
return false;
}
if (enumerable.Count() != other.Count() || enumerable.Except(other).Any())
{
return false;
}
foreach (T value in enumerable.Distinct())
{
if (enumerable.Count(v => Equals(v, value)) != other.Count(v => Equals(v, value)))
{
return false;
}
}
return true;
}
在您的情况下,我想您可以这样做:zeichenSatz[0].ContentEquals(zeichenSatz[1]);
您可以使用Linq:
bool areEqual = a.SequenceEqual(b);
您需要什么结果?请提供测试输入、预期输出和应用程序实际产生的输出。
bool areEqual = a.SequenceEqual(b);