c#为具有字母的文本框值添加值 [英] c# add value to textbox value that has letters

查看:78
本文介绍了c#为具有字母的文本框值添加值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个相同形式的文本框:textbox1和textbox2



textbox1用户输入3个字母和数字,所以它看起来像这样:abc111为例



我需要textbox2为textbox1中的数字加1并给出如下结果:



abc112



怎么做代码plz

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

推荐答案

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


-KR


你必须在'alphabetic'中拆分输入字符串(即abc111)一个(即abc)和数字111(您可以使用字母字符串长度为三个字符的事实)然后将后者转换为数字。增加这样的数字并使用'alphabetic'字符串和格式正确的递增数字为 textbox2 构建一个新字符串。
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.


这篇关于c#为具有字母的文本框值添加值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆