[英]How to split using multiple characters?
I am trying to make error free user input. 我正在尝试使用户输入无错误。 When there is a one split symbol user might type it and create an error which I must fix before executing creating more lines of code. 如果有一个拆分符号,则用户可能会键入它并创建一个错误,在执行创建更多代码行之前,我必须解决该错误。 Is there a way of splitting a string using for example $%$
instead of just $
character? 是否可以使用$%$
而不是$
字符来分割字符串?
This is how I do splitting using one character: 这是我使用一个字符进行拆分的方法:
if (!lastUsed.EmptyFile())
{
string[] allSettings = lastUsed.Text.Split('$');
int settingCount = 0;
foreach (string setting in allSettings)
{
settingCount++;
if (settingCount == 1)
{
txtText.Text = setting;
}
else if (settingCount == 2)
{
if (setting == "0") tbType.SelectedTab = tbInterval;
else tbType.SelectedTab = tbRange;
}
else if (settingCount == 3)
{
nudInterval.Value = decimal.Parse(setting);
}
else if (settingCount == 4)
{
nudMin.Value = decimal.Parse(setting);
}
else if (settingCount == 5)
{
nudMax.Value = decimal.Parse(setting);
}
}
}
You can use a string as the delimiter. 您可以使用字符串作为分隔符。
string[] delim = new string[] {"$%$"};
string[] allSettings = lastUsed.Text.Split(delim, StringSplitOptions.None);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.