如何在dotnet中分割a值 [英] how to split the a value in dotnet
本文介绍了如何在dotnet中分割a值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
hi
我有一个像这样的值1:3想要使用asp.net和c#拆分此值,我有两个变量a,b想要将这些拆分值传递给这些变量.
谢谢
hi
i have a value like this 1:3 want to split this value using asp.net and c#, i have two varaiables a,b want to pass those split values to these variables.
Thanks
推荐答案
您可以使用拆分 [
You can use split[^] method to do this.
Assuming you want to split 1:3 to 1 and 3, here is a sample:
string strData = "1:3";
string[] strSplitResult = strData.Split(":".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
string a = "";
string b = "";
if (strSplitResult.Length > 1)
{
a = strSplitResult[0];
b = strSplitResult[1];
}
在C#中
string a, b;
string no = "1:3";
a = no.Split(':')[0];
b = no.Split(':')[1];
假定它在字符串中:
Assuming it is in a string:
string s = "1:3";
string[] parts = s.Split(':');
int a, b;
if (parts.Length >= 2)
{
if (int.TryParse(parts[0], out a) && int.TryParse(parts[1], out b))
{
...
}
}
这篇关于如何在dotnet中分割a值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文