110,532
社区成员
发帖
与我相关
我的任务
分享
var source = richTextBox1.Lines.Where(s => s.Trim() != "").Select(s => s.Select((c, index) => new KeyValuePair<int, char>(index, c))).ToList();
var tmp = source.First();
for (int i = 1; i < source.Count; i++)
{
tmp = tmp.Join(source[i], f => f, s => s, (f, s) => f);
}
var lst = source.First().Select(i => i.Key).Except(tmp.Select(i => i.Key));
谢谢各位的解答,结贴!
string s1 = "1100 0100 1101 0011 1100 0100 1000 0000 0000 0000 0010 0100 1100 0000 1000 0000 0101 0000 0000 0000 0000 0000 1000 0000 0000 1000 0001 1010";
string s2 = "1100 0100 1101 0011 1010 0100 1000 0000 0000 0000 0010 0100 1100 0000 1000 0000 0101 0000 0000 0000 0000 0000 1000 0000 0000 1000 0001 1010";
string s3 = "1100 0100 1101 0011 0110 0100 1000 0000 0000 0000 0010 0100 1100 0000 1000 0000 0101 0000 0000 0000 0000 0000 1000 0000 0000 1000 0001 1010";
List<string> myArr = new List<string> { s1, s2, s3 };
int ColSum = 0;
int Row = 0;
List<int> Result = new List<int>();
for (int Col=0; Col < myArr[0].Length; Col++)
{
if(myArr[0][Col].ToString()==" ")
{
continue;
}
for (Row=0; Row < myArr.Count; Row++)
{
ColSum += Convert.ToInt32(myArr[Row][Col].ToString());
}
if(!(ColSum==Row || ColSum==0))
{
Result.Add(Col);
}
ColSum = 0;
}
static void Main(string[] args)
{
string[] a =
{
"1100 0100 1101 0011 1100 0100 1000 0000 0000 0000 0010 0100 1100 0000 1000 0000 0101 0000 0000 0000 0000 0000 1000 0000 0000 1000 0001 1010",
"1100 0100 1101 0011 1010 0100 1000 0000 0000 0000 0010 0100 1100 0000 1000 0000 0101 0000 0000 0000 0000 0000 1000 0000 0000 1000 0001 1010",
"1100 0100 1101 0011 0110 0100 1000 0000 0000 0000 0010 0100 1100 0000 1000 0000 0101 0000 0000 0000 0000 0000 1000 0000 0000 1000 0001 1010",
};
for (var i = 0; i < a[0].Length; i++)
{
for (var j = 0; j < a.Length; j++)
{
if (a[j][i] != a[0][i])
{
Console.WriteLine(i);
break;
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
namespace Inhertied
{
class IL_Method_Test
{
public static void Main()
{
var s1 = "1100 0100 1101 0011 1100 0100 1000 0000 0000 0000 0010 0100 1100 0000 1000 0000 0101 0000 0000 0000 0000 0000 1000 0000 0000 1000 0001 1010";
var s2 = "1100 0100 1101 0011 1010 0100 1000 0000 0000 0000 0010 0100 1100 0000 1000 0000 0101 0000 0000 0000 0000 0000 1000 0000 0000 1000 0001 1010";
var s3 = "1100 0100 1101 0011 0110 0100 1000 0000 0000 0000 0010 0100 1100 0000 1000 0000 0101 0000 0000 0000 0000 0000 1000 0000 0000 1000 0001 1010";
var arr = new List<string> { s1, s2, s3 };
var result = from i in Enumerable.Range(0, arr[0].Length)
where !判断字符完全一致(arr, i)
select i;
foreach (var i in result)
{
Console.Write("第{0}个字符有差异:", i);
foreach (var s in arr)
Console.Write(s[i]);
Console.WriteLine();
}
Console.WriteLine(".....................按任意键结束");
Console.ReadKey();
}
private static bool 判断字符完全一致(List<string> arr, int i)
{
var c = arr[0][i];
for (var j = 1; j < arr.Count; j++)
if (arr[j][i] != c)
return false;
return true;
}
}
}
var arr = new List<string> ();
........
var result = from i in Enumerable.Range(0, arr[0].Length)
where !判断arr中某位置的字符完全一致(arr, i)
select i;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
List<string> array = new List<string>();
//array.Add("1100 ……");
if (array.Count < 1)
return;
int minLength = array.Min(m => m.Length);
for (int idx = 0; idx < minLength; idx++)
{
char ch = array[0][idx];
for (int i = 1; i < array.Count; i++)
{
if (array[i][idx] != ch)
Console.WriteLine(idx);
}
}
}
}
}
var s1 = "1100 0100 1101 0011 1100 0100 1000 0000 0000 0000 0010 0100 1100 0000 1000 0000 0101 0000 0000 0000 0000 0000 1000 0000 0000 1000 0001 1010";
var s2 = "1100 0100 1101 0011 1010 0100 1000 0000 0000 0000 0010 0100 1100 0000 1000 0000 0101 0000 0000 0000 0000 0000 1000 0000 0000 1000 0001 1010";
var query = from a in s1.ToArray().Select((x, index) => new { k = index, v = x })
from b in s2.ToArray().Select((x, index) => new { k = index, v = x })
where a.k == b.k && a.v != b.v
select a.k;
Console.WriteLine(string.Join(",", query));
应该是用循环更好