UnicodeBefore (Unicode function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (→‎Examples: add new example using new [ & ] entities)
m (→‎Examples: add word)
Line 33: Line 33:


==Examples==
==Examples==
In the following requests, the substring that precedes the left square bracket (<tt>[</tt>) character is excerpted by <var>UnicodeBefore</var>. Two variations of the request are shown because of an enhancement for square-bracket handling introduced in version 7.6 of Model 204.
In the following requests, the substring that precedes the left square bracket (<tt>[</tt>) character representation is excerpted by <var>UnicodeBefore</var>. Two variations of the request are shown because of an enhancement for square-bracket handling introduced in version 7.6 of Model 204.
<ul>
<ul>
<li>For version 7.6 and higher:  
<li>For version 7.6 and higher:  

Revision as of 22:22, 9 May 2016

Part of string before a substring (Unicode class)

[Introduced in Model 204 7.5]


UnicodeBefore operates on a Unicode variable or string and returns the portion of that string before a user-specified delimiter. To get the portion of the string after a delimiter, use the UnicodeAfter string method.

Syntax

%outUnicode = unicode:UnicodeAfter( substring, [Start= number])

Syntax terms

%outUnicode A Unicode variable to hold the output of the parsed input string, unicode.
unicode A Unicode string that holds the string to be parsed.
substring A Unicode string that holds the separator character or characters on which parsing occurs.
Start This numeric value is the starting point for parsing. The default value is 1, indicating the beginning of the string.

This is a name required argument, and it cannot be 0. If a value larger than the string length is specified, the method returns a null string.

Usage notes

  • If a starting value is entered, the %outUnicode value is the content of the string that begins before the first occurrence of the delimiter substring encountered after the specified start point, or that ends at the end of the string if the delimiter token is not encountered.

    The delimiter string is not a list of individual delimiters; it is a single delimiter which may be multiple characters. If your delimiter is "ok", the method looks for occurrences of those two lowercase letters, and it returns a value that starts before the first occurrence found after the starting point.

  • This method is always case-sensitive.

Examples

In the following requests, the substring that precedes the left square bracket ([) character representation is excerpted by UnicodeBefore. Two variations of the request are shown because of an enhancement for square-bracket handling introduced in version 7.6 of Model 204.

  • For version 7.6 and higher:

    The left and right square brackets used in this example are created using the [ and ] XHTML entities, added by zap maintenance in version 7.6. These entities are recommended because, depending on your browser's codepage, the square bracket characters may or may not render correctly:

    begin %x is unicode %x = 'Released in 1966, Manos: The Hands of Fate [is a D-minus] ' with - 'of a B movie: Its plot, about desert-dwelling pagans, makes little sense.' printText {%x:unicodeBefore('[')} end

    The request result is:

    Released in 1966, Manos: The Hands of Fate

  • For version 7.5:

    The left and right square brackets below are created using the U method and placed in variables %sqL and %sqR. The variables are inserted into a Unicode string and used to parse that string:

    begin %sqL is string len 1 initial("[":u) static %sqR is string len 1 initial("]":u) static %x is unicode %x = 'Released in 1966, Manos: The Hands of Fate ' with %sqL with - ' is a D-minus ' with %sqR with - ' of a B movie: Its plot, about desert-dwelling pagans, makes little sense.' printText {%x:unicodeBefore(%sqL)} end

    Again, the request result is:

    Released in 1966, Manos: The Hands of Fate

See also