'Split a string by a number for get multiple string values [duplicate]
Hi want to get a string cutted by a number like "abcdefgh" (split by 4) string[] = "ab, cd, ef, gh".
Solution 1:[1]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | JBatstone |
