我有以下字符串:分割字符串成2 C#块
string input ="this is a testx";
我需要把空格去掉,然后拆分输入两个大块,这样我就可以单独每两个字母的过程:
th的是在ES TX
我试图与删除空格:
input=input.Remove(input.IndexOf(' '),1);
Ť母鸡我不能做与分裂...
我有以下字符串:分割字符串成2 C#块
string input ="this is a testx";
我需要把空格去掉,然后拆分输入两个大块,这样我就可以单独每两个字母的过程:
th的是在ES TX
我试图与删除空格:
input=input.Remove(input.IndexOf(' '),1);
Ť母鸡我不能做与分裂...
IEnumerable<string> output = input
.Replace(" ", string.Empty)
.Select((ch, i) => new{ch, grp = i/2})
.GroupBy(x => x.grp)
.Select(g => string.Concat(g.Select(x => x.ch)));
或更理智:)
input = input.Replace(" ", string.Empty);
IEnumerable<string> output =
Enumerable.Range(0, input.Length/2).Select(x => input.Substring(x * 2, 2));
,你可以按如下方式使用输出:
foreach(var item in output)
{
Console.WriteLine(item);
}
什么代码中有你试过吗?你是否收到异常或不正确的结果? – 2014-09-22 00:25:22
问题是什么? – Dmitry 2014-09-22 00:25:33