i have a text box that contains a string. The strings length is always a multiple of 5. How can i break the string into chunks of 5 and store them in a string arrary?
Printable View
i have a text box that contains a string. The strings length is always a multiple of 5. How can i break the string into chunks of 5 and store them in a string arrary?
if there is a special character to endicate the end of 1 5 char block then:
or you could go through each character and return it the 5 characters per chunk of 5 charactersCode:
string[] theChunks = this.TextBox1.Text.Split(someIndicator);
if I understood that correctly....
No there is no seperator. Ill give your second answer a try.
Code:string text = this.textBox1.Text;
int chunkCount = text.Length / 5;
string[] chunks = new string[chunkCount];
int startIndex = 0;
for (int i = 0; i < chunks.Length; i++)
{
chunks[i] = text.Substring(startIndex, 5);
startIndex += 5;
}