Click here to Skip to main content
15,917,709 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have 2 textboxes in the same form : textbox1 and textbox2

in textbox1 user enters 3 letters and number so it will look like this : abc111 as an example

I need textbox2 to add 1 to the numbers in textbox1 and give result like this :

abc112

how to do that in code plz
Posted

C#
Regex reg = new Regex(@"([a-zA-Z]+)(\d+)");
Match result = reg.Match(TextBox1.Text);

string txt = result.Groups[1].Value;
string num = result.Groups[2].Value;

TextBox2.Text = txt + (int.Parse(num) + 1);

-KR
 
Share this answer
 
Comments
Ahmed Zoeil 20-Oct-15 9:03am    
regex and Match have redlines under them says : the type or namespace could not be found
Ahmed Zoeil 20-Oct-15 9:09am    
I got it had to add using System.Text.RegularExpressions;
Krunal Rohit 20-Oct-15 9:40am    
Hmm, you have to.

-KR
Krunal Rohit 20-Oct-15 12:16pm    
Why is it down-voted even after OP accepted the solution ?

-KR
Ahmed Zoeil 20-Oct-15 12:56pm    
down voted !!?
You have to split the input string (that is "abc111") in the 'alphabetic' one (namely "abc") and 'numeric' "111" (you may use the fact that 'alphabetic' string is three characters long) and then convert the latter into a number. Increment such number and built a fresh string for textbox2 using the 'alphabetic' string and the properly formatted incremented number.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900