See below.<br><br><div class="gmail_quote">On 3 January 2012 13:01, Lalitha <span dir="ltr"><<a href="mailto:v.lalithasri@gmail.com">v.lalithasri@gmail.com</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">
Hi all,<br>
<br>
I am working on drools. I would like to remove Special characters which<br>
are existed in the data i.e. replacing special characters with null.<br>
Following is the code:<br>
<br>
rule "Wild Character validation"<br>
when<br>
c : CustomerInfo(customerName != "");<br></blockquote><div><br>It is much better to write a condition that selects just the objects you're really interested here, i.e., the ones containing the characters you want to eliminate, thus:<br>
<br> c: CustomerInfo( customerName matches ".*[*#].*" )<br> </div><blockquote class="gmail_quote" style="border-left:1px solid rgb(204,204,204);margin:0pt 0pt 0pt 0.8ex;padding-left:1ex">
<br>
then<br>
<br>
int l = c.length();<br>
int ch = 0;<br>
int i = 0;<br>
for (i = 0; i < l; i++) {<br>
if (data.charAt(i) != "*"|| data.charAt(i) != "#"){<br>
continue;<br>
}<br>
ch++;<br>
data.setCharAt(i, "");<br>
}<br>
c.setCustomerName(data);<br>
end<br></blockquote><div><br>I assume that you assume that data is a String, but you haven't assigned it a value. And even if you do, you cannot modify a String. This is simple Java coding, and I'd say that you should go and study a Java text book.<br>
<br>Here's the right hand side code I'd use:<br><br>String data = c.getCustomerName().replaceAll( "[*#]", "" );<br>modify( c ){ setCustomerName( data ) }<br><br>I don't think you want to replace these characters with "null". I think you just want to remove them from the string, so that<br>
"foo*bar#baz" becomes "foobarbaz".<br><br>-W<br><br><br><br><br> </div><blockquote class="gmail_quote" style="border-left:1px solid rgb(204,204,204);margin:0pt 0pt 0pt 0.8ex;padding-left:1ex">
<br>
Is there any wrong in this code? If so please help me out. Waiting for your<br>
suggestion .<br>
<br>
Thanks and Regards,<br>
<span class="HOEnZb"><font color="#888888">Lalitha.<br>
<br>
--<br>
View this message in context: <a href="http://drools.46999.n3.nabble.com/Removing-Special-Characters-tp3628821p3628821.html" target="_blank">http://drools.46999.n3.nabble.com/Removing-Special-Characters-tp3628821p3628821.html</a><br>
Sent from the Drools: User forum mailing list archive at Nabble.com.<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></span></blockquote></div><br>