如何删除连字符“-”但在删除 C# 中的连字符之前计算数字?
How to remove hyphen "-" but count the number before remove the hyphen in C#?
我有一个文本框、一个标签和一个按钮,文本框格式如下:
23-44-33-32-34-05-40-12
我想要当用户单击按钮然后删除所有“-”但计算每个数字并存储一些字符串变量然后在标签上显示总数或字符串。
提前致谢。
试试这个:
//Getting the textbox data and assigning to a string
string initialstring = textbox1.text;
//Calculating the total number of words available
int totalcount = initialstring.Split('-').Length;
//Replacing the '-' character which need to be reassign to textbox
string formattedstring = initialstring.Replace("-", " ");
//Assigning formatted data to textbox
textbox1.text = formattedstring;
你能做的就是先替换角色,然后再依靠它。您可能会喜欢以下内容:
var countOfCharacters = mystring.Replace("-", "").Length;
youlabel.Text = countOfCharacters;
很简单:
var nrOfChars = yourTextBox.Text.Count(c => c != '-')
我有一个文本框、一个标签和一个按钮,文本框格式如下:
23-44-33-32-34-05-40-12
我想要当用户单击按钮然后删除所有“-”但计算每个数字并存储一些字符串变量然后在标签上显示总数或字符串。
提前致谢。
试试这个:
//Getting the textbox data and assigning to a string
string initialstring = textbox1.text;
//Calculating the total number of words available
int totalcount = initialstring.Split('-').Length;
//Replacing the '-' character which need to be reassign to textbox
string formattedstring = initialstring.Replace("-", " ");
//Assigning formatted data to textbox
textbox1.text = formattedstring;
你能做的就是先替换角色,然后再依靠它。您可能会喜欢以下内容:
var countOfCharacters = mystring.Replace("-", "").Length;
youlabel.Text = countOfCharacters;
很简单:
var nrOfChars = yourTextBox.Text.Count(c => c != '-')