Replace the case-insensitive method in ASP

Source: Internet
Author: User

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

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

The syntax of the Replace function includes the following parameters:

Parameter description
Expression is required. The string expression contains the substring to be replaced.
Find is required. The substring to be searched.
Replacewith is required. The substring used for replacement.
Start is optional. Expression to start searching for the position of the substring. If omitted, the default value is 1. Must be used when associating with count
Count option. Number of substrings to replace. If this parameter is omitted, the default value is-1, indicating all possible replacements. It must be used in association with start.
Compare is optional. Indicates the value of the comparison type used to calculate the substring. For values, see the "Settings" section. If omitted, the default value is 0, which means binary comparison is required.

Set
The compare parameter can have the following values:
Constant Value description
VbBinaryCompare 0 performs binary comparison.
VbTextCompare 1 performs text comparison.

Return Value
Replace returns the following values:
If Replace returns
Expression is a zero-length, zero-length string ("").
Expression is Null.
Find a zero-length expression copy.
Replacewith is a zero-length expression copy, in which all content specified by the find parameter is deleted.
Start> Len (expression) Zero-length string.
Count is a copy of 0 expression.

Description
The Return Value of the Replace function is a string after replacement (starting from the position specified by start to the end of the expression string), rather than a copy of the original string from start to end.
The following example uses the Replace function to return a string:

Copy codeThe Code is as follows: Dim MyString
MyString = Replace ("XXpXXPXXp", "p", "Y") 'binary comparison starts from 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: directly use the replace function provided by ASP, which is also the simplest method.

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

Replace function parameters:
Parameter 1: Source string
Parameter 2: the character to be replaced
Parameter 3: new character ., It is required to replace some characters in the source string with new specified characters.
Parameter 4: The value is 1. Specify that the string is searched from the first character.
Parameter 5: The value is-1, indicating that each substring must be replaced.
Parameter 6: The value of 1 indicates that the comparison of strings is case insensitive.

(Highlight keywords) Two Functions
Method 2: replace the specified character with a regular expression that is case insensitive.
The following is the function source code:

Copy codeThe Code is as follows: '// function: String replacement
'// Parameter: Regular Expression, string to be replaced, string to be replaced
Public Function ReplaceTest (patrn, mStr, replStr)
Dim regEx
Set regEx = New RegExp
RegEx. Pattern = patrn
RegEx. IgnoreCase = True
RegEx. Global = True
ReplaceTest = regEx. Replace (mStr, replStr)
Set regEx = Nothing
End Function
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.