characterfilter(
characterfilter(
TEXT
,
FILTER
)

The characterfilter( function scans and filters text on a character by character basis.

Parameters

This function has two parameters:

text – is the text to be scanned and filtered.

filter – is a formula that produces a text result. This formula will be calculated for each character in the text parameter. The result will be appended to the value returned by the formula. The result of this formula isn’t limited to a single character, but may be several characters or zero characters (“”). Within the formula you can use the import( function to retrieve the original character, or the seq( function to retrieve the position of the character within the text. Note: The overall formula must be quoted (using quote characters that are not used anywhere in the formula itself, see the examples below).

Description

The characterfilter( function scans text on a character by character basis. Rather than using a fixed processing method to filter the text, it allows the programmer to supply a formula that is used over and over again to filter each individual character of the text. As it scans the input text, it builds a new text field or variable. The contents of the new text is based on the result of the formula which is applied to each character of the original text. The formula can use the import( function to retrieve the original character, or the seq( function to retrieve the position of the character within the text.

Let’s review some examples that illustrate the operation of the characterfilter( function. This example converts a string of characters into a comma separated array.

    characterfilter("abcd",{import()+","}) ☞ a,b,c,d,

This example converts text into a set of hex digits.

    characterfilter("abcd",{hexstr(asc(import()))[-2,-1]+" "}) ☞ 61 62 63 64

This example shows how characterfilter also works with Unicode characters.

    characterfilter("a⏎b™c",{asc(import())+" "}) ☞ 97 9166 98 8482 99

In the example above we have retrieved the chr( equivalent of each character.

Notice that in both of these examples the formula is surrounded by curly braces to quote the formula. So the formula:

    import()+","

must be quoted like this:

    {import()+","}

or this:

    |||import()+","|||

Actually, you can use whatever quotes you want, as long as they are not used within the formula itself.

You can also put the formula into a variable, then use that variable in the characterfilter( function. In that case you need to quote the formula when you assign it to the variable, but you should not quote the variable name.

    local filterformula
    filterformula={import()+","}
    message characterfilter("abcd",filterformula)

Error Messages

characterfilter( syntax error in filter formula – This error will occur if the filter formula itself contains a syntax error.

See Also

- characterfilter -- scans and filters text on a character by character basis.
- textfilter( -- scans and filters text on a character by character basis.

History

Version | Status | Notes
10.0 | No Change | Carried over from Panorama 6.0 but now also supports Unicode characters.