基于变量吐出字符串。 [英] spitting string based on variables .
问题描述
大家好,
希望你过得愉快。
我的问题是:
i有以下字符串例如
(0)1002(10)1
此字符串应分为2个字符串,如下所示:
string item_code = 1002;总是在(0)之后的是物品代码
string unit = 1;总是在(10)之后的是单位< br $> b $ b
请帮忙做这个
最好的问候,
Hadi
Hello all,
Hope that you are having a great times.
my question is :
i have the following string for example "
(0)1002(10)1
this string should be divided into 2 strings as follows :
string item_code = 1002 ; always what comes after(0) is the item code
string unit = 1 ; always what comes after(10) is the unit
Please help to do this one
Best Regards,
Hadi
推荐答案
尝试这样的事情:
Try something like this:
String data = "(0)1002(10)1";
String[] values = data.Split("(10)");
检查要制作的数组的长度确定值存在。
索引0:从开头删除'(0)'
索引1:单位
祝你好运!
Check the length of the array to make sure the values are present.
index 0: remove '(0)' from the beginning
index 1: unit
Good luck!
string str = string.Empty;
str = "(0)1002(10)1";
string str1 = string.Empty;
string str2 = string.Empty;
int l = str.Length;
int f1 = 0;
int f2 = 0;
for (int i = 0; i < l;i++ )
{
if (str[i].ToString() == "(")
{
f1 = f1 + 1;
}
else if (str[i].ToString() == ")")
{
f2 = f2 + 1;
}
if(i>2 && f1==1)
{
str1 = str1 + str[i].ToString();
}
if(str[i].ToString() != ")" && f2==2)
{
str2 = str2 + str[i].ToString();
}
}
string str ="(0)1002(10)1;
string item_code = str.Substring(str.IndexOf("(0)"),str.IndexOf("(10)"))。替换(" (0)","");
string unit = str.Substring(str.IndexOf("(10)"))。替换("(10)" ,";
string str = "(0)1002(10)1;
string item_code = str.Substring(str.IndexOf("(0)"), str.IndexOf("(10)")).Replace("(0)", "");
string unit = str.Substring(str.IndexOf("(10)")).Replace("(10)", "");
这篇关于基于变量吐出字符串。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!