SoFunction
Updated on 2025-03-10

ASP to replace the case-insensitive method

Let's take a look at the detailed parameters of Replace

describe
Returns a string where a specified number of substrings is replaced with another substring.
grammar
Replace(expression, find, replacewith[, compare[, count[, start]]])

The syntax of the Replace function has the following parameters:

Parameter Description
expression Required. String expression Contains the substring to replace.
Find Required option. The substring being searched for.
replacewith Required option. Substring used for replacement.
start Optional. Start searching for the location of the substring in expression. If omitted, the default value is 1. Must use it when associated with count
count is optional. The number of substring replacements performed. If omitted, the default value is -1, indicating that all possible replacements are made. Must be used when associated with start.
compare Optional. Indicates the value of the comparison type used when calculating the substring. For values, see the Settings section. If omitted, the default value is 0, which means that binary comparisons must be performed.

set up
The compare parameter can have the following values:
Constant Value Description
vbBinaryCompare 0 Perform binary comparison.
vbTextCompare 1 Perform text comparison.

Return value
Replace returns the following values:
If Replace returns
expression is zero length zero length string ("").
Expression is Null error.
find is a copy of zero length expression.
replacewith is a copy of zero-length expression, where all content specified by the find parameter is deleted.
start > Len(expression) Zero-length string.
count is a copy of 0 expression.

illustrate
The return value of the Replace function is a string that has been replaced (start from the position specified by start to the end of the expression string), rather than a copy of the original string from the beginning to the end.
The following example uses the Replace function to return a string:

Copy the codeThe code is as follows:

Dim MyString
MyString = Replace("XXpXXPXXp", "p", "Y") 'Binary comparison starts at the left end of the string. Returns "XXYXXPXXY".
MyString = Replace("XXpXXPXXp", "p", "Y", 'Text comparison starts with the third character. Returns "YXXYXXY". 3, -1, 1)

Method 1: Use ASP's own function to replace it. This is also the easiest method.

title=replace(title,"DF","SD",1,-1,1)

Detailed explanation of the parameters of the replace function:
Parameter 1: Source string
Parameter 2: Characters to be replaced
Parameter 3: New character. , , to replace certain characters in the source string with newly specified characters
Parameter 4: Value is 1. Specify searching for the string starting from the first character
Parameter 5: Value is -1 Specifies that each substring must be replaced
Parameter 6: Value 1 The comparison of the specified string is case-insensitive.


Two functions (highlight keywords)
Method 2: Replace the specified character with regular case insensitive
The following is the function source code:

Copy the codeThe code is as follows:

'//Function: String replacement
'//Article: Regular expression, replaced string, replaced string
 Public Function ReplaceTest(patrn, mStr, replStr)
  Dim regEx
  Set regEx = New RegExp
  = patrn
  = True  
  = True
  ReplaceTest = (mStr, replStr)
  Set regEx = Nothing
 End Function