Hello

Can anyone please help me out in how to get or read two values from single textbox.
i.e when i read the first value it should be stored in string str1 , when i click button the textbox shld be cleared and shld wait to accept second value.The second value shld be stored in str2.
This is like a simple calculator wherein we enter many number in one textbox.

Thank You

Recommended Answers

All 6 Replies

If it`s a simple calculator way you need only one TextBox for the values? If You wish to take two values from one TextBox you need some char to separate the values for example char '+':
Example:
If the user enter "5 + 5" in the TextBox you can use '+' for separation like that:

string allValue = textBox.Text;
            string firstValue = String.Empty;
            string secondValue = String.Empty;

            int getIndexOfPlus = allValue.IndexOf('+');
            
            for (int i = 0; i < allValue.Length; i++)
            {
                if (i < getIndexOfPlus)
                {
                    firstValue += allValue[i];
                }
                else if (i > getIndexOfPlus)
                {
                    secondValue += allValue[i];
                }
            }
            
            firstValue = firstValue.Trim(); // To remove empty spaces
            secondValue = secondValue.Trim(); // To Remove Empty spaces

If this don`t help you. Please answer me !!! Sorry for my bad English !!!

Way you need only one TextBox if may I ask? And if you try to enter first value. Click Button. After that enter the second value in the same TextBox. Why you doing so hard for you? I think you need to think more about your simplicity of your calculator. Because I don't think for simple. If you use your way to do your calculator you will need to counting how much times is clicked on Button. I don`t know how to answer your question because for me it`s sound like you wish to build a house from playing cards and after that to living in this house !!! Sorry for my bad English !!!

commented: You give good advise, improve on your English, don't feel sorry about it. :) +7

You need some sort of indicator to tell you which string to use

String str1;
String str2;
Boolean UseStringOne = true;
private void button1_Click(object sender, EventArgs e) {
    if (UseStringOne) {
        str1 = textBox1.Text;
    } else {
        str2 = textBox1.Text;
    }
    textBox1.Text = String.Empty;
    UseStringOne = UseStringOne ? false : true;
}

This code will alternate between using str1 and str2 each time the button is pressed.

Thanks a lot guys :) :) keep rocking

Program 1: Write a program in Asp.Net C# accept two string from user to copy first user inputted string to

another string with the number of copied characters and check whether a second user inputted is present in

the first user inputted string or not? Replace first user inputted strings lowercase characters by uppercase and

vice-versa also calculate the Highest frequency of character in the second user inputted? and sort a user string

in ascending order?

Ex:

First user inputted string is: This is a string to be copied.

Second user inputted string is: KAran213.

Output:

The user inputted first string is: This is a string to be copied.

The user inputted second string is: KAran213.

The Copied string is: This is a string to be copied.

Number of characters copied: 31

The Second string is not exists in the string.

After Case changed the string is: tHIS iS a tEST sTRING.

The Highest frequency of character 'e' appears number of times: 4

After sorting the string appears like: 123AaKnr

please give me ans for above question

commented: You didn't show any effort to solve this yourself. -3
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.