Customer Portal

REPLACING non-ascii/non printable characters

Comments 3

  • Avatar
    admin
    0
    Comment actions Permalink
    Hi,

    I guess you used wrong order of operations :-) It should be:


    $out.0.content = removeNonAscii(removeDiacritic($in.0.content));


    So removeDiacritic transforms "Žluťoučký kůň ☯" to "Zlutoucky kun ☯" first. Then removeNonAscii transform "Zlutoucky kun ☯" to "'Zlutoucky kun ".
  • Avatar
    shakespeare101
    0
    Comment actions Permalink
    My input content is of fixed length...
    $out.0.content = removeNonAscii(removeDiacritic($in.0.content));

    Is there a way to remove the nonAscii and maintain the spacing?

    So...if the content is a name field with an extra non ASCII character I need to have the field length stay the same or it will throw off the rest of the record field assignments in the metadata.
    so...in effect i need "Zlutoucky kun ☯" to change to "Zlutoucky kun " or "Zlutoucky kun *" - basically I just need to maintain the spacing.

    Any ideas? Is replace() my best bet?
  • Avatar
    imriskal
    0
    Comment actions Permalink
    Hello, Shakespeare101,

    I still do not get why you want to use remove functions. These functions remove characters without any replacement so your result strings would obviously be shorter. If I get you right, function replace(string, string, string) would be much better for you. The second string argument of this function is a regular expression.

    For example, this function replaces any NonAscii character with asterisk character:
    $out.0.content = replace($in.0.content,"[^\\x00-\\x7F]","*");

    Try to google something like "regexp non ascii characters" for more examples. Also, keep in mind that special characters in regular expression in CTL has to be escaped with backslashes.

    And the last thing, I believe space is an Ascii character, see http://www.asciitable.com/index/asciifull.gif
    Therefore removeNonAscii(string) maintains spacing automatically.

    I hope I helped you.

    Best regards,

Please sign in to leave a comment.