I가 다음 문자열 : 나는 공백을 제거하고 두 덩어리로 입력을 분할, 그래서 개별적으로 모든 두 글자를 처리 할 필요가분할 문자열
string input ="this is a testx";
:
번째 난에 공백을 제거하려고
TX ES에서이다 :
input=input.Remove(input.IndexOf(' '),1);
T 내가 분할로 많은 것을 할 수없는 암탉 ... 더 현명
I가 다음 문자열 : 나는 공백을 제거하고 두 덩어리로 입력을 분할, 그래서 개별적으로 모든 두 글자를 처리 할 필요가분할 문자열
string input ="this is a testx";
:
번째 난에 공백을 제거하려고
TX ES에서이다 :
input=input.Remove(input.IndexOf(' '),1);
T 내가 분할로 많은 것을 할 수없는 암탉 ... 더 현명
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);
}
어떤 코드를 가지고 해봤습니까? 예외 또는 잘못된 결과가 표시됩니까? –
무엇이 문제입니까? – Dmitry