+ 1
c# how i can make the button clear one number or one letter without clear the all numbers in c#
7 Answers
+ 2
show your code and we will try to help.
with your very limited info, I would suggest on button click, take the number or string and run it thru a method to remove what you want and then return it with the new number or string
+ 2
I see.. Assuming you know how button clicks are handled.
when you click the button, take the textbox input and store it in a variable. pass this variable into a method to remove the #4 and then store your new number without the 4 in it into the variable. assign the text of your textbox to have the value of your new variable
+ 2
Here is an example I threw together
// for the example, when you click the button it would store your textbox value to a variable like
static String inbox="1234";
I made a temporary variable to build the new string without the number 4
static String tempVar;
//This method takes a string, such as the variable you store from your textbox, and removes the number 4 from it.
static void clearStuff(String x){
foreach(char c in x){
if(c=='4'){}
else{tempVar=tempVar+c;}
}
//instead of this method writing the new variable as I did here, change this part to assign your textbox text
Console.WriteLine(tempVar);
}
+ 2
Here it is without comments if you want to copy and play with it.
static String inbox="1234";
static String tempVar;
static void clearStuff(String x){
foreach(char c in x){
if(c=='4'){}
else{tempVar=tempVar+c;}
}
Console.WriteLine(tempVar);
}
+ 1
look like this I add to textbox number 1234 ok.
now I want clear just number 4 number 4 just