In addition to what Frank has stated, it should be noted that the sequence of<br>transformations<br> SF -> S<br> S -> VOL<br>performed by String.replace() can be simplified to a single transformation using replaceAll with a pattern:<br>
<br>rule "Rule12 for parameter 1"<br>
when<br>
$plan : plan( $p1: parameter1 matches ".*S.*" )<br>then<br> modify( $plan ){<br> setParameter1( $p1.replaceAll( "SF?", "VOL" ) )<br> }<br>end<br><br>-W<br><br><br><div class="gmail_quote">
On 18 November 2011 16:20, FrankVhh <span dir="ltr"><<a href="mailto:frank.vanhoenshoven@agserv.eu">frank.vanhoenshoven@agserv.eu</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Cautionç This is answered after only a quick look.<br>
<br>
You must notify the engie that a change has occured by calling update(plan);<br>
in the RHS. Not calling update will modify the object, but the engine will<br>
not take these changes into account.<br>
<br>
Regards,<br>
Frank<br>
<br>
<br>
fiitkar wrote:<br>
><br>
> Hello,<br>
><br>
> I've problem with string replacement.<br>
> See the following example.<br>
> Input string: SF<br>
> I've written two simple rules:<br>
> The first one transforms SF to S<br>
> The second one transforms S to VOL.<br>
> The expected output after the transformation should be S, but I get VOL.<br>
> (as for example for the rules: A->Z, Z->K, input A, output will be Z and<br>
> not K).<br>
> So my question is how to avoid this problem (I suppose the problem is that<br>
> the first transformation returns substring of the input and moreover does<br>
> exist another transformation rule for it).<br>
><br>
> rule "Rule1 for parameter 1"<br>
> salience 2<br>
> when<br>
> plan : plan( parameter1 matches ".*SF.*" )<br>
> then<br>
> plan.setParameter1(plan.getParameter1().replace("SF","S"));<br>
><br>
> end<br>
><br>
><br>
> rule "Rule2 for parameter 1"<br>
> salience 1<br>
> when<br>
> plan : plan( parameter1 matches ".*S.*" )<br>
> then<br>
> plan.setParameter1(plan.getParameter1().replace("S","VOL"));<br>
> end<br>
><br>
> Thank you for your response.<br>
> Peter<br>
><br>
<font color="#888888"><br>
<br>
--<br>
View this message in context: <a href="http://drools.46999.n3.nabble.com/string-replace-collision-problem-tp3518826p3518860.html" target="_blank">http://drools.46999.n3.nabble.com/string-replace-collision-problem-tp3518826p3518860.html</a><br>
Sent from the Drools: User forum mailing list archive at Nabble.com.<br>
<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</font></blockquote></div><br>