有这样一条线,需要与С#:需要与С#。我怎么能得到33?
"1/33 "
"1/32 "
"1/31 "
我怎样才能得到33?
在С++:
sprintf("*/%d&*", value)
如何使用с#做到这一点?我需要一个int a = string(...),它会返回33?
有这样一条线,需要与С#:需要与С#。我怎么能得到33?
"1/33 "
"1/32 "
"1/31 "
我怎样才能得到33?
在С++:
sprintf("*/%d&*", value)
如何使用с#做到这一点?我需要一个int a = string(...),它会返回33?
选项1:使用Replace
string yourString="1/33 "; // Your string if I understand the Q
yourString=yourString.Replace("1/","").Replace(" ", ""); // Replace 1/ and with nothing Thank you @Mike
int number; // The number that will be convert
if(int.TryParse(yourString, out number)) // Convert string to int if the string is a number
{
// Do something
// Number is 33 it this case
}
选项2:使用Substring
(@Mike评论)
string yourString="1/33 "; // Your string if I understand the Q
string n33 = yourString.Substring(yourString.IndexOf("/") + 1, yourString.IndexOf("&") - 2);
int number; // The number that will be convert
if(int.TryParse(n33 , out number)) // Convert string to int if the string is a number
{
// Do something
// Number is 33 it this case
}
严重的是,什么? – Guy
你想打印:'“1/{something}”'?.. –
我想问题是关于'正则表达式',他想从第一个字符串中获得数字33。 – Ahmar