Replace Function

Microchip TCP/IP Stack

Microchip TCP/IP Stack Help
Replace Function
C
SHORT Replace(
    BYTE * vExpression, 
    ROM BYTE * vFind, 
    ROM BYTE * vReplacement, 
    WORD wMaxLen, 
    BOOL bSearchCaseInsensitive
);
Description

Searches a string (vExpression) and replaces all instances of a particular substring (vFind) with a new string (vReplacement). The start offset to being searching and a maximum number of replacements can be specified. The search can be performed in a case sensitive or case insensitive manner.

Preconditions

This function is commented out by default to save code space because it is not used by any current stack features. However, if you want to use it, go ahead and uncomment it. It has been tested, so it (should) work correctly.

Parameters
Parameters 
Description 
vExpression 
Null terminated string to search and make replacements within. 
vFind 
Null terminated string to search for. 
vReplacement 
Null terminated string to replace all instances of vFind with. 
wMaxLen 
Maximum length of the output vExpression string if string expansion is going to occur (replacement length is longer than find length). If the replacements will cause this maximum string length to be exceeded, then no replacements will be made and a negative result will be returned, indicating failure. If the replacement length is shorter or equal to the search length, then this parameter is ignored. 
bSearchCaseInsensitive 
Boolean indicating if the search should be performed in a case insensitive manner. Specify TRUE for case insensitive searches (slower) or FALSE for case sensitive searching (faster). 
Returns

If zero or greater, indicates the count of how many replacements were made. If less than zero (negative result), indicates that wMaxLen was too small to make the necessary replacements. In this case, no replacements were made.

Remarks

If the replacement string length is shorter than or equal to the search string length and the search string occurs in multiple overlapping locations (ex: expression is "aaa", find is "aa", and replacement is "bb") then the first find match occuring when searching from left to right will be replaced. (ex: output expression will be "bba"). 

However, if the replacement string length is longer than the search string length, the search will occur starting from the end of the string and proceed to the beginning (right to left searching). In this case if the expression was "aaa", find was "aa", and replacement was "bbb", then the final output expression will be "abbb".

Microchip TCP/IP Stack 5.42.08 - June 15, 2013
Copyright © 2012 Microchip Technology, Inc.  All rights reserved.