Groups | Blog | Home
all groups > dotnet framework > december 2004 >

dotnet framework : String Manipulation - Problems??


GTDriver
12/28/2004 9:25:02 PM
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.

--
Sincerely,

R. Thomas, aka Xtreme.Net
12/28/2004 9:43:06 PM
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[i].ToString());
}

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

Hth...
R. Thomas

[quoted text, click to view]
Jon Skeet [C# MVP]
12/29/2004 9:08:30 AM
[quoted text, click to view]

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

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
AddThis Social Bookmark Button