Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi again,

I want my text boxes to break down the text within them into different variables. For example, if I paste 3000 characters of text into the text box I want the first thousands to var = text1, the second thousand to var = text2 etc...

I use the following code to save all the text to a variable at the moment:

C++
public void button1_Click(object sender, EventArgs e)
       {
           var list = textBox1.Text;
       }


One method I was thinking was to capture the first 1000 characters, save them to a var and then delete them. Then just loop that until all the text is gone.

Any other methods?

Thanks in advance.
Posted

1 solution

Use String.Substring Method (Int32, Int32)[^].

[Agent_Spock]

Example in your case:-
var list = textBox1.Text.Substring(0,1000);

This would give you first 1000 letters and for second one thousand use
var list = textBox1.Text.Substring(1000,1000);
 
Share this answer
 
v2
Comments
wiley_25 22-Feb-14 12:56pm    
In what context do I use it?<pre "c#">
string testlist = Substring(0, 1000)textBox1.Text;</pre>
, that returns errors.
You should do like...

string testlist = textBox1.Text.Substring(0, 1000);
wiley_25 22-Feb-14 13:39pm    
Sweet works fine, the issue now is that if a bulk of text is under 1000 it will not fire.
It will work if the length is 1000 or more.
Else, you need to specify the length instead of 1000.

Please accept the answer.

Thanks,
Tadit
wiley_25 22-Feb-14 14:27pm    
Annoyingly I can't find anywhere if I can do for example: Substring(0, ANYNUMBER);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900