473,410 Members | 1,875 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,410 software developers and data experts.

Dividing text in a textBox

Hello
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.

Thanks in advance.

Nov 15 '05 #1
6 4124
"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
Nov 15 '05 #2
You can use a regex, but I don't use them enouph to ever remember the syntax
without going backinto the doco. However this is pretty easy. If you know
you will always split on "====" (and not "==" for example) then just
preparse the string and replace "====" with a comma "," for example. Now
you should have "Apple,Bat,Candy". Now just do a String.Split into a
string[]:

string s = "Bob====Paul====Bill";
s = s.Replace("====", ",");
string[] sa = s.Split(',');
foreach (string sepString in sa)
{
Console.WriteLine(sepString);
}

--
William Stacey, DNS MVP

"Tomomichi Amano" <to*********@hotmail.com> wrote in message
news:ey**************@tk2msftngp13.phx.gbl...
Hello
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.

Thanks in advance.

Nov 15 '05 #3
Tomomichi, That's a perfect use case for the String.Split() method. You can
split on the ===='s and then take the resulting array of strings and assign
them to the appropriate text boxes.

--
Greg Ewing [MVP]
http://www.citidc.com
"Tomomichi Amano" <to*********@hotmail.com> wrote in message
news:ey**************@tk2msftngp13.phx.gbl...
Hello
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.

Thanks in advance.

Nov 15 '05 #4
"Greg Ewing [MVP]" <gewing@_NO_SPAM_gewing.com> wrote:
That's a perfect use case for the String.Split()
method. You can split on the ===='s


String.Split can only split on characters, not substrings, so it's not quite
that simple.

P.

--
www.CL4.org
Nov 15 '05 #5
True, if you need to do multiple characters than Regex.Split() is where you
should look. You can define any regex expression to split upon.

--
Greg Ewing [MVP]
http://www.citidc.com

"Paul E Collins" <fi******************@CL4.org> wrote in message
news:bl**********@hercules.btinternet.com...
"Greg Ewing [MVP]" <gewing@_NO_SPAM_gewing.com> wrote:
That's a perfect use case for the String.Split()
method. You can split on the ===='s
String.Split can only split on characters, not substrings, so it's not

quite that simple.

P.

--
www.CL4.org

Nov 15 '05 #6
string.Replace(@"====", "\0").Split(new char[] {'\0'}) will acheive the
split into the array.

"Paul E Collins" <fi******************@CL4.org> wrote in message
news:bl**********@hercules.btinternet.com...
"Greg Ewing [MVP]" <gewing@_NO_SPAM_gewing.com> wrote:
That's a perfect use case for the String.Split()
method. You can split on the ===='s
String.Split can only split on characters, not substrings, so it's not

quite that simple.

P.

--
www.CL4.org

Nov 15 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Dennis C. Drumm | last post by:
Is there a way to modify the standard context menu shown when someone right clicks in a windows text box and that would work for all open windows applications? The standard context menu for...
5
by: Steve S | last post by:
Heres what I want to do...User types into a texbox, clicks a button, the button saves that text to a file. The problem is that when I click the submit button, any changes made to the textbox are...
6
by: Lance Geeck | last post by:
I have a simple form where I am using a dataset called Client. On the data entry screen, there are name, address, city state and zip. I have the fields bound to the dataset field. (Properties...
16
by: mj.redfox.mj | last post by:
Can anyone help? I have a textbox which I'm programatically adding by using the following code: txtTest = New TextBox txtTest.ID = "txtLeft" + cntCount.ToString...
0
by: andytsummers | last post by:
Hi I have tried to implement drag and drop by using the following code but I have several problems. 1. When you put your mouse over selected text the cursor is still the i-beam and therefore...
4
by: pablorp80 | last post by:
Hello, Here is what I need: I need the focus and the cursor set to a textbox named txtGT, every time no matter if it is the first page load or whether it is a postback. Here is the problem: I...
2
kcdoell
by: kcdoell | last post by:
Hello: I have three unbound text boxes in which I have the following calculations in the control source of each box: FCST Total; =Nz(DSum("","ReQryForecast"," >= 75"),0) Budget Total; ...
0
by: chandrasekhar | last post by:
Hi I have developed a web page with some controls. I put all of them in session variables. I passed this values in the page. When an user enter some data in form fields and click the buttton ,...
1
by: semomaniz | last post by:
I have a form where i have created the form dynamically. First i manually added a panel control to the web page. Then i added another panel dynamically and inside this panel i created tables. I have...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.