"Tomomichi Amano" <to*********@hotmail.com> wrote:
I want to divide the text in "textBox11" to ten
separate textBoxes1 to 10, separated with
a divider text "====".
So, if the text in textBox11 is "Apple====Bat
====Candy====Dime..." the text in textBox1
is "Apple", textBox2 is "Bat", textBox3 is "Candy,
textBox4 is "Dime" and so on.
Here is one way to split up the string.
Doing things with TextBoxes is up to you. (You'll probably find it easier if
you have an array of TextBoxes, rather than individual ones with numbered
names.)
string strAll = "Apple====Bat====Candy====Dime";
ArrayList words = new ArrayList();
while (strAll != "" && strAll != "====")
{
int iDelimPos = strAll.IndexOf("====");
if (iDelimPos == 0)
{
// Found a leading delimiter
strAll = strAll.Substring("====".Length);
}
else if (iDelimPos > -1)
{
// Found a word followed by '===='
words.Add(strAll.Substring(0, iDelimPos));
strAll = strAll.Substring(strAll.IndexOf("===="));
}
else
{
// Found the last word
words.Add(strAll);
strAll = "";
}
}
for (int iWord = 0; iWord < words.Count; iWord++)
{
// do something with words[iWord]
}
P.
--
www.CL4.org