How replace in ASP replaces case-insensitive

Source: Internet
Author: User
Tags comparison numeric numeric value regular expression

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

Describe

Returns a string in which a specified number of substrings are replaced with another substring.

Grammar

Replace (expression, find, replacewith[, compare[, count[, start]])

The syntax for the Replace function has the following parameters:

Parameter description

expression Required option. A string expression contains a substring to override.

Find required Options. The substring being searched for.

ReplaceWith required option. The substring to replace.

Start option. The location at which to start searching for substrings in expression. If omitted, the default value is 1. When associating with count, you must use the

Count can be selected. The number of execution substring substitutions. If omitted, the default value is-1, which means that all possible substitutions are made. Must be used when associating with start.

Compare can be selected. Indicates the numeric value of the comparison type to use when calculating the substring. For numeric values, see the "Settings" section. If omitted, the default value is 0, which means that binary comparisons must be made.

Set up

The Compare parameter can have the following values:

Constant numerical description

Vbbinarycompare 0 performs binary comparisons.

vbTextCompare 1 performs a text comparison.

return value

Replace returns the following values:

If Replace returns

Expression is a zero-length 0-length string ("").

Expression is a Null error.

Find is a zero-length expression copy.

ReplaceWith is a zero-length expression copy that deletes all the content specified by the find parameter.

Start > Len (expression) 0 length string.

Count is a copy of 0 expression.

Description

The return value of the Replace function is a string that is replaced (starting at the position specified by start to the end of the expression string), rather than a copy from the beginning to the end of the original string.

The following example uses the Replace function to return a string:

Copy code code 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 One: Direct use of ASP with function Replace this is also the easiest way

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

Replace function parameter detailed:

Parameter 1: source string

Parameter 2: The character to be replaced

Parameter 3: The new character. , either to replace some characters in the source string with the newly specified character

Parameter 4: value is 1. Specifies that the string be searched starting at the first character

Parameter 5: The value is-1 specifies that each substring is to be replaced

Parameter 6: A value of 1 specifies that comparisons of strings are case-insensitive.

Two functions (highlighting keywords)

Method 2: Replace the specified character with a regular case-insensitive case

Here is the function source code:

Copy code code as follows:

'//function: string substitution

'//parameter: regular expression, replaced string, replacement string

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.