See below.

On 3 January 2012 13:01, Lalitha <v.lalithasri@gmail.com> wrote:
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 != "");

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:

    c: CustomerInfo( customerName matches ".*[*#].*" )
 

 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

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.

Here's the right hand side code I'd use:

String data = c.getCustomerName().replaceAll( "[*#]", "" );
modify( c ){ setCustomerName( data ) }

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
"foo*bar#baz" becomes "foobarbaz".

-W




 

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