It will work but it isn't at all declarative but instead very procedural - it 
is effectively the same as retrieving all the rows from the database and then 
filtering them yourself.
You've also failed to inform drools that you have updated the CustomerInfo 
object.
Assuming customerName is a string in terms of java code it is also extremely 
inefficient and verbose (and badly broken as data isn't defined).
String has the replace and replaceAll methods to replace characters far more 
efficiently than the approach below.

I'd probably have something like

Rule "Wild char validation"
When
        c: CustomerInfo(name : customerName matches ".*([\*#].*") //any string 
containing a * or a #
then
        modify(c) {
                setCustomerName(name.replaceAll("[\*#]", "")); //replace any * 
or # with ""
        }
end

if you don't like regex you could also do

Rule "Wild char validation"
When
        c: CustomerInfo(eval(customerName.contains("*") || 
customerName.contains("#"))) //any string containing a * or a #
then
        String name = c.getCustomerName();
        name = name.replace("#","");
        name = name.replace("*","");
        modify(c) {
                setCustomerName(name);
        }
end

other similar variations are available - depending on your throughput you may 
want to experiment with whether there are many differences in terms of 
performance.

Thomas

> -----Original Message-----
> From: rules-users-boun...@lists.jboss.org [mailto:rules-users-
> boun...@lists.jboss.org] On Behalf Of Lalitha
> Sent: 03 January 2012 12:02
> To: rules-users@lists.jboss.org
> Subject: [rules-users] Removing Special Characters
>
> Hi all,
>
>   I am working on drools. I would like to remove Special characters which are
> existed in the data i.e. replacing special characters with null.
> Following is the code:
>
> rule "Wild Character validation"
>   when
>     c : CustomerInfo(customerName != "");
>
>   then
>
>    int l = c.length();
>    int ch = 0;
>    int i = 0;
>    for (i = 0; i < l; i++) {
>       if (data.charAt(i) != "*"|| data.charAt(i) != "#"){
>          continue;
>         }
>         ch++;
>         data.setCharAt(i, "");
>       }
>    c.setCustomerName(data);
> end
>
> Is there any wrong in this code? If so please help me out. Waiting for your
> suggestion .
>
> Thanks and Regards,
> Lalitha.
>
> --
> View this message in context: http://drools.46999.n3.nabble.com/Removing-
> Special-Characters-tp3628821p3628821.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> rules-users@lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users


**************************************************************************************
This message is confidential and intended only for the addressee. If you have 
received this message in error, please immediately notify the 
postmas...@nds.com and delete it from your system as well as any copies. The 
content of e-mails as well as traffic data may be monitored by NDS for 
employment and security purposes. To protect the environment please do not 
print this e-mail unless necessary.

NDS Limited. Registered Office: One London Road, Staines, Middlesex, TW18 4EX, 
United Kingdom. A company registered in England and Wales. Registered no. 
3080780. VAT no. GB 603 8808 40-00
**************************************************************************************

_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users

Reply via email to