Forum Discussion

FICO's avatar
FICO
Community Manager
3 years ago

Remove Spaces from a STRING

Hi,

I am using FICO DM to write a Rule. For this Rule I need match the Postal Code from one source to the postal code from another source. The issue I am facing is that once source has a blank space in the string and before I can match the postal codes I need to remove that space.

Example:

PostalCode1 is A1B2F5

PostalCode2 is A1B 2F5

My rule is -

compressString(input.request.postalCode1) = compressString(input.request.postalCode2)

But for some reason I do not seem to make it work. Is there something that I am missing?

3 Replies

  • FICO's avatar
    FICO
    Community Manager

    You can use the replaceAll() method to remove the space from a string. For example, the statements in SRL could be something like below:

    PostalCode2 is a string initially "A1B 2F5";

    Postalcode1 = PostalCode2.replaceAll("\\s", "").

  • FICO's avatar
    FICO
    Community Manager

    Thanks! It worked perfectly...sorry as I am very new to the language I have another question.

    I see that the replaceAll works with spaces. Would you be able to sent me a list that I can use to remove characters as well (i.e. within the brackets)?

    For Example if i need to remove Special Characters from the above (example Postal Code was "L7A ?1W#4 to "L7A1W4")?

    Thanks!

  • FICO's avatar
    FICO
    Community Manager

    You can use the substitute() method of RegularExpression class to replace any characters in a string. Please refer to the Blaze Advisor documentation for more details.