在字符串中查找整数
Finding whole number in string
我有一个输入号码。比方说 545。例如,现在我有这个字符串:string trying = "658;984;756;545;2000;5450"
如您所见,这个字符串中有 545
,但也有 5450
我只想找到我输入的数字是 545
但在我当前的代码中我也找到 5450
。我当前的代码:
MySet.MyRole = "658;984;756;545;2000;5450";
if (MySet.MyRole is null || MySet.MyRole.IsEmpty())
{
setupSet.MyRole1 = true;
}
else if (MySet.MyRole.Contains(Number.ToString()))
{
setupSet.MyRole1 = true;
}
我想你可以 Split
Returns a string array that contains the substrings in this instance
that are delimited by elements of a specified string or Unicode
character array.
然后使用Contains
Determines whether an element is in the List.
var input = "658;984;756;545;2000;5450";
var result = input.Split(';').Contains("545");
我有一个输入号码。比方说 545。例如,现在我有这个字符串:string trying = "658;984;756;545;2000;5450"
如您所见,这个字符串中有 545
,但也有 5450
我只想找到我输入的数字是 545
但在我当前的代码中我也找到 5450
。我当前的代码:
MySet.MyRole = "658;984;756;545;2000;5450";
if (MySet.MyRole is null || MySet.MyRole.IsEmpty())
{
setupSet.MyRole1 = true;
}
else if (MySet.MyRole.Contains(Number.ToString()))
{
setupSet.MyRole1 = true;
}
我想你可以 Split
Returns a string array that contains the substrings in this instance that are delimited by elements of a specified string or Unicode character array.
然后使用Contains
Determines whether an element is in the List.
var input = "658;984;756;545;2000;5450";
var result = input.Split(';').Contains("545");