ASP replace () string substitution introduction

Source: Internet
Author: User
Tags chr numeric numeric value

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

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

Parameters
Expression

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

Find

Required option. The substring being searched for.

ReplaceWith

Required option. The substring to replace.

Start

Options available. 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

Options available. 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

Options available. 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 a binary comparison must be made, a Chinese self-study programming network, www.zxbc.cn.

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.

Does the explanation above look foggy? Then explain in Chinese in detail:

The syntax for Replace in ASP is:
Replace ("string", "string to be substituted", "substituted string", "Start character position", "replace count")

The syntax for the replace of VBScript in ASP is: replace ("string", "string to be substituted", "substituted string")

Replace in VBScript () Details:
Function: Finds in a string, substituting the specified string.
Format: replace (Strtobesearched,strsearchfor,strreplacewith [, Start[,count[,compare]]])
Parameter: strtobesearched is a string; strSearchFor is the substring being looked for; strReplaceWith is the substring to be substituted. Start,count,compare is any option.

Example:

The code is as follows Copy Code
<%
Strtest= "This is an apple."
Response.Write Replace (strtest, "Apple", "orange")
%>

Output result: This is an orange.

Instance

A specified number of substrings are replaced with another substring.

The code is as follows Copy Code

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

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)

Instance

Replace line Wrap

objRS to Rs object name

The code is as follows Copy Code
<%
..........
Strtmp=replace (objRS ("content"), Chr (+), "<br>")
...........
%>
<%=strTmp%>

Note that it is CHR (13) instead of char (13)

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.