在字符串中查找特定模式 [英] Find specific pattern in a string

查看:68
本文介绍了在字符串中查找特定模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hai,


在一个文本框中我的文字为

"(20/100)+ pay1 * pay2" .it'是一个公式。并存储在特定的

变量中。

string strformula ="(20/100)+ pay1 * pay2" ;


我必须用变量''pay1''的值代替& ''pay2''和

找到该strformula的价值。

可以告诉我如何找到''pay1''和''pay2''变量

strformula。这很紧急并立即回复。

提前致谢。

Hai ,

in a textbox am having text as
"(20/100)+pay1*pay2" .it''s a formula. and stored in a particular
variable.
string strformula="(20/100)+pay1*pay2" ;

i''ve to substitute the value of the variable ''pay1'' & ''pay2'' and
finding the value of that strformula.
can any onr tell me how to find ''pay1'' and ''pay2'' in the variable
strformula. it''s urgent and reply immediately.
Thanks in advance.

推荐答案

他们总是会去被称为pay1的和pay2?公式

总是一样吗?如果没有,可以改变什么?


你需要提供更多不同公式的例子(如果你有不同公式的b
)我们知道什么

问题的参数是。一个例子是不够的。

Are they always going to be called "pay1" and "pay2"? Is the formula
always going to be the same? If not, what can change?

You need to give more examples of different formulas (if you can have
different formulas) in order that we know what the parameters of the
problem are. One example isn''t enough.


公式可能是

pay5 + pay6





(pay6 * pay7)* 20/100



可能需要任何字母数字组合

the formula may be
pay5+pay6

or

(pay6*pay7)*20/100
or
it may take any alphanumeric combinations


< ks *********** @ gmail.com>写道:
<ks***********@gmail.com> wrote:
公式可能是
pay5 + pay6



(pay6 * pay7)* 20/100 或
它可能需要任何字母数字组合
the formula may be
pay5+pay6

or

(pay6*pay7)*20/100
or
it may take any alphanumeric combinations




你知道你需要更换什么,并且它不会发生
另一种形式的
?例如,如果您需要替换pay1,使用

" 5",你需要应付:


pay1 + repay1


并避免成为


5 + re5





如果没有,只需使用string.Replace :


string changed = original.Replace(" pay1"," 5");


-

Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet 博客: http: //www.msmvps.com/jon.skeet

如果回复该群组,请不要给我发邮件



Do you know exactly what you need to replace, and that it won''t occur
in another form? For instance, if you needed to replace "pay1" with
"5", would you need to cope with:

pay1+repay1

and avoid that becoming

5+re5

?

If not, just use string.Replace:

string changed = original.Replace ("pay1", "5");

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too


这篇关于在字符串中查找特定模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆