Hi want to get a string cutted by a number like "abcdefgh" (split by 4) string[] = "ab, cd, ef, gh".
Asked
Active
Viewed 85 times
-3
-
What approaches have you tried so far? – GoodboY May 04 '22 at 20:44
-
Nothing, i don't found something do what i want. It's everytime split by character like "\" or something with delimiter. – IdkWhatShouldIUse May 04 '22 at 20:48
1 Answers
0
Duplicate: Splitting a string into chunks of a certain size
static IEnumerable<string> Split(string str, int chunkSize)
{
return Enumerable.Range(0, str.Length / chunkSize)
.Select(i => str.Substring(i * chunkSize, chunkSize));
}
This answer was my favorite.

JBatstone
- 167
- 7
-
-
string[] array = Split("abcdefgh",4).ToArray(); or do you mean "abcdefgh" has to be a string array? – JBatstone May 04 '22 at 21:02