简体   繁体   中英

How to check for end of string in textbox in c#

I am a noob, I am stuck on this code.

I am taking input from user in a textbox and saving it in a string. Then I want to run a loop until the string ends and I put if condition for different characters....

string que;
que = textBlock1.Text;
        while (!que[i].Equals('\0'))
        {
            int res;
            if (int.TryParse(que[i].ToString(), out res) || que[i].ToString() == "x" || que[i].ToString() == "/" || que[i].ToString() == "^")
            {
                f[j] = f[j] + que[i].ToString();
            }
            if (que[i].ToString() == "+" || que[i].ToString() == "-")
                j++;
            i++;

        }

Can someone please guide me? What should I do??

Use:

textBlock1.Text.Lenght

That way you can know the length of the string.

您是否尝试过foreach(char c in que){ /*your code*/ }

If you want to just run through the loop until the end of the string, a simple condition like this should do:

        int i = 0;
        while (i < que.Length )
        {
             // Your code
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM