Search and Replace Strings with Replace()

Replace() returns a string in which matching substrings have been replaced. Optional arguments control the starting position, number of replacements and comparison mode.

Syntax

Replace(string_var, string_find, string_replace, start, count, comparetype)

The defaults begin at position 1, replace all matches, and use the default comparison rules. Prefer named constants such as vbBinaryCompare and vbTextCompare when specifying comparison behavior.

Replace every exact-case match

Dim string_var, string_find, string_replace
string_var="Welcome to ASP section for ASP tutorials"
string_find="ASP"
string_replace="PHP"
Response.Write Replace(string_var, string_find, string_replace)

Output

Welcome to PHP section for PHP tutorials

Binary comparison does not match different case

string_find="asp"

Output

Welcome to ASP section for ASP tutorials

Replace one match using text comparison

Response.Write Replace(string_var, string_find, string_replace, 1, 1, vbTextCompare)

Output

Welcome to PHP section for ASP tutorials

The equivalent argument values are:

start=1
count=1
comparetype=vbTextCompare

The original PHP cross-reference is retained: PHP str_replace().


ASP Home






✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer