String Manipulation - Problems??

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I would like to interate through each character in textboxcontrol.text.
However, I'm having trouble accomplishing this.

If I assign the value of a text property to a string variable and then do
strVar.Length I'm not getting the value I expect for the length. When I try
for strVar(1), it says strVar is not an array.

How do I evaluate each character in textboxcontrol.text? This is probably
vary simple but I must be overlooking something.
 
Hi,
you can use this piece of code to do what you asked :
char[] arrStr;
arrStr = Convert.ToString(textBox1.Text).ToCharArray();
for(int i = 0 ; i < arrStr.Length ; i ++)
{
MessageBox.Show(arrStr.ToString());
}

P.S : If this post helped you, please click 'Yes' on top of this post

Hth...
R. Thomas
 
GTDriver said:
I would like to interate through each character in textboxcontrol.text.
However, I'm having trouble accomplishing this.

If I assign the value of a text property to a string variable and then do
strVar.Length I'm not getting the value I expect for the length. When I try
for strVar(1), it says strVar is not an array.

How do I evaluate each character in textboxcontrol.text? This is probably
vary simple but I must be overlooking something.

If you're using VB.NET, you can use strVar.Chars(1) etc.

You could also use a For Each loop:

For Each c as char in strVar
....
Next
 
Back
Top