我怎样才能解析一部分字符串? [英] How can I parse a portion of string ?
问题描述
我的字符串格式如下!
string data = @usertext(输入您的代码,日期,测试,bla,bla,bla, ......);
// 或
string data = @usertext(提供您的数据,日期,测试,bla,bla,bla,......);
即使它可以像
string data = @usertext(输入您的代码);
// 或
string data = @usertext(提供你的数据)
这意味着括号的部分可以用逗号分隔,甚至可以用可以只有一个像第二个样本的部分。
首先代码将检查字符串中的是否有@usertext。如果在那里找到@usertext那么它将解析字符串&将从第一个或第二个字符串样本中取出括号的第一部分输入您的代码或提供您的数据。然后我将使用这部分获得价值。然后我将使用此值替换整个字符串。
请记住@usertext部分之前或之后可能有很多东西像
< pre lang =c#> string data = @variable(composite,@ certext(Give your data,data,test));
// 或
string data = Menu,@ usertext(Give your data),Table;
我的工作仅限于@usertext(提供您的数据)或@usertext(提供您的数据,数据,测试)。我需要选择第一个括号的第一部分,然后我将使用此部分获得价值,整个@usertext(Give Your data,data,test)将被此vaue取代。
使用substring方法解析字符串
I have a string format like following !
string data = @usertext(Enter Your Code, date, test, bla, bla,bla,......) ;
//OR
string data = @usertext(Give Your data, date, test, bla, bla,bla,......) ;
Even it can be like
string data = @usertext(Enter Your Code) ;
//OR
string data = @usertext(Give Your data)
That means the portion of bracket can be separated using comma or even there can have only one portion like second sample.
At first the code will check "is there @usertext" in the string. If @usertext is found there then it will parse the string & will take the first portion of bracket "Enter Your Code" or "Give Your data" from first or second sample of string. then I will get value using this portion. Then I will replace whole string by using this value.
Please keep in mind that there can have many thing before or after @usertext portion Like
string data = @variable(composite, @usertext(Give Your data,data,test));
//OR
string data = Menu, @usertext(Give Your data), Table;
My work is only with the portion of "@usertext(Give Your data)" OR @usertext(Give Your data,data,test). I need to pick the first portion of first bracket then I will get value using this portion and whole "@usertext(Give Your data,data,test)" will be replaced by this vaue.
Use substring method to parse the string
这篇关于我怎样才能解析一部分字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!