如何识别字符串

时间:2015-08-15 08:56:56

标签: c# .net operators

如果我有这样的字符串:

string a = "<=1.0.5" or "=1.0.5" or "!=1.0.5";

如何将带有运算符的零件和带有版本号的零件分别转换为变量?

1 个答案:

答案 0 :(得分:1)

如果字符串中始终存在相等的运算符:

string a = "<=1.0.5"; // "=1.0.5" or "!=1.0.5" or "==1.0.5"
int indx = a.LastIndexOf('=') + 1;  
string op = a.Substring(0, indx);  //<=
string version = a.Substring(indx); //1.0.5