Jump to content

ULSFindAttr: Difference between revisions

From EDM2
Created page with "==Description== Searches a string for the first character that fits the specified attribute criterion. NOTE: The 'start' and 'max' parameters both specify a number of cha..."
 
Ak120 (talk | contribs)
mNo edit summary
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
==Description==
Searches a string for the first character that fits the specified attribute criterion.
Searches a string for the first character that fits the specified attribute criterion.


    NOTE: The 'start' and 'max' parameters both specify a number of characters,
;NOTE: The 'start' and 'max' parameters both specify a number of characters, not a number of bytes. (In the case of MBCS codepages, these may not be the same thing).
          not a number of bytes. (In the case of MBCS codepages, these may not
          be the same thing).


==Arguments==
==Arguments==
ULSFindAttr( string, attribute [, start] [, max] [, flag] [, codepage] [, locale] )
ULSFindAttr( string, attribute [, start] [, max] [, flag] [, codepage] [, locale])
   


Parameters:
===Parameters===
      string   The input string to be searched.
;string:The input string to be searched.
 
;attribute:The name of the attribute to search for. Valid attribute names are listed under the [[ULSQueryAttr]] function description. The name is not case sensitive.
      attribute The name of the attribute to search for. Valid attribute names
;start:The character position within the string to start searching from. Must fall between 1 and the string length (in characters). Defaults to 1 (the start of the string) if not specified.
                are listed under the ULSQueryAttr function description (below).
;max:The maximum number of characters to search. Defaults to the length of the string (in characters) if not specified.
                The name is not case sensitive.
;flag:The type of search to perform. Only the first character is significant, and (if specified) must be one of the following values:
 
::T = True: find the first character that matches the specified attribute. This is the default.
      start     The character position within the string to start searching
::F = False: find the first character that does not match the specified attribute.
                from. Must fall between 1 and the string length (in
;codepage:The source codepage (a positive integer). This is the codepage with which <string> is encoded (i.e. under which it would display correctly). The default is the current process codepage.
                characters). Defaults to 1 (the start of the string) if not
;locale:The name of the locale whose text-attribute rules are to be used. Locale names are usually of the form "xx_YY", where "xx" is a language and YY is a country (e.g. "en_US", "zh_TW", "it_IT", etc.)  The default is to use the current locale as defined by the LANG and LC_* environment variables.
                specified.
 
      max       The maximum number of characters to search. Defaults to the
                length of the string (in characters) if not specified.
 
      flag     The type of search to perform. Only the first character is
                significant, and (if specified) must be one of the following
                values:
                  T = True: find the first character that matches the specified
                      attribute. This is the default.
                  F = False: find the first character that does not match the
                      specified attribute.
 
      codepage The source codepage (a positive integer). This is the codepage
                with which <string> is encoded (i.e. under which it would
                display correctly). The default is the current process
                codepage.
 
      locale   The name of the locale whose text-attribute rules are to be
                used. Locale names are usually of the form "xx_YY", where "xx"
                is a language and YY is a country (e.g. "en_US", "zh_TW",
                "it_IT", etc.)  The default is to use the current locale as
                defined by the LANG and LC_* environment variables.


==Return Value==
==Return Value==
Line 48: Line 21:


==Example==
==Example==
    Example:
Example:
 
<code>
        /* Input string (encoded for codepage 850) */
/* Input string (encoded for codepage 850) */
        string = 'We had lunch at a caf‚ in Reykjav¡k.'
string = 'We had lunch at a caf‚ in Reykjav¡k.'
        SAY string
SAY string
 
        /* Search string for the first non-ASCII character */
/* Search string for the first non-ASCII character */
        c = ULSFindAttr( string, 'ascii',,,'F')
c = ULSFindAttr( string, 'ascii',,,'F')
        IF ULSERR \= '0' THEN
IF ULSERR \= '0' THEN
            SAY ULSERR
      SAY ULSERR
        ELSE
  ELSE
            SAY 'The first non-ASCII character is at position:' c
      SAY 'The first non-ASCII character is at position:' c
==Output==
</code>
Output:
We had lunch at a caf‚ in Reykjav¡k.
The first non-ASCII character is at position: 22


        We had lunch at a caf‚ in Reykjav¡k.
[[Category:RxULS]]
        The first non-ASCII character is at position: 22

Latest revision as of 14:29, 14 August 2017

Searches a string for the first character that fits the specified attribute criterion.

NOTE
The 'start' and 'max' parameters both specify a number of characters, not a number of bytes. (In the case of MBCS codepages, these may not be the same thing).

Arguments

ULSFindAttr( string, attribute [, start] [, max] [, flag] [, codepage] [, locale])

Parameters

string
The input string to be searched.
attribute
The name of the attribute to search for. Valid attribute names are listed under the ULSQueryAttr function description. The name is not case sensitive.
start
The character position within the string to start searching from. Must fall between 1 and the string length (in characters). Defaults to 1 (the start of the string) if not specified.
max
The maximum number of characters to search. Defaults to the length of the string (in characters) if not specified.
flag
The type of search to perform. Only the first character is significant, and (if specified) must be one of the following values:
T = True: find the first character that matches the specified attribute. This is the default.
F = False: find the first character that does not match the specified attribute.
codepage
The source codepage (a positive integer). This is the codepage with which <string> is encoded (i.e. under which it would display correctly). The default is the current process codepage.
locale
The name of the locale whose text-attribute rules are to be used. Locale names are usually of the form "xx_YY", where "xx" is a language and YY is a country (e.g. "en_US", "zh_TW", "it_IT", etc.) The default is to use the current locale as defined by the LANG and LC_* environment variables.

Return Value

The character position of the first match, or 0 if no matching characters were found. If an error occurs, an empty string ("") is returned and the global ULSERR variable will be set to a non-zero value.

Example

Example:

/* Input string (encoded for codepage 850) */
string = 'We had lunch at a caf‚ in Reykjav¡k.'
SAY string

/* Search string for the first non-ASCII character */
c = ULSFindAttr( string, 'ascii',,,'F')
IF ULSERR \= '0' THEN
     SAY ULSERR
  ELSE
     SAY 'The first non-ASCII character is at position:' c

Output:

We had lunch at a caf‚ in Reykjav¡k.

The first non-ASCII character is at position: 22