Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: Text /
Chapter 5 - Text Utilities / Text Utilities Reference
Routines / Searching for and Replacing Strings


ReplaceText

The ReplaceText function searches text, replacing all instances of a string in that text with another string. ReplaceText searches on a character-by-character basis (as opposed to byte-by-byte), so it works properly for all script systems.

FUNCTION ReplaceText (baseText, substitutionText: Handle;
                      key: Str15): Integer;
baseText
A handle to the string in which ReplaceText is to substitute text.
substitutionText
A handle to the string that ReplaceText uses as substitute text.
key
A Pascal string of less than 16 bytes that ReplaceText searches for.
DESCRIPTION
ReplaceText searches the text specified by the baseText parameter for instances of the string in the key parameter and replaces each instance with the text specified by the substitutionText parameter. ReplaceText searches on a character-by-character basis. It recognizes 2-byte characters in script systems that contain them and advances the search appropriately after encountering a 2-byte character.

ReplaceText returns an integer value. If the returned value is positive, it indicates the number of substitutions performed; if it is negative, it indicates an error. The constant noErr is returned if there was no error and no substitutions were performed.

SPECIAL CONSIDERATIONS
ReplaceText may move memory; your application should not call this function at interrupt time.

ASSEMBLY-LANGUAGE INFORMATION
The trap macro and routine selector for the ReplaceText function are
Trap macroSelector
_ScriptUtil$820C FFDC

RESULT CODES
nilHandleErr 109GetHandleSize fails on baseText or substitutionText
memFullErr108SetHandleSize fails on baseText
memWZErr-111GetHandleSize fails on baseText or substitutionText

Previous Book Contents Book Index Next

© Apple Computer, Inc.
6 JUL 1996