YouTip LogoYouTip

Func Replace

# VBScript Replace Function * * Complete VBScript Reference Manual](#) * * * The Replace function replaces a specified part of a string with another string a specified number of times. ### Syntax Replace(string,find,replacewith[,start[,count[,compare]]]) | Parameter | Description | | :--- | :--- | | string | Required. The string to be searched. | | find | Required. The substring to be replaced. | | replacewith | Required. The substring used for replacement. | | start | Optional. Specifies the starting position. Default value is 1. All characters before the starting position will be deleted. | | count | Optional. Specifies the number of replacements to perform. Default value is -1, meaning all possible replacements will be performed. | | compare | Optional. Specifies the type of string comparison to use. Default is 0. Possible values are: * 0 = vbBinaryCompare - Performs binary comparison * 1 = vbTextCompare - Performs textual comparison | ## Examples ## Example 1 Replace the word "beautiful" with "fantastic": txt="This is a beautiful day!" document.write(Replace(txt,"beautiful","fantastic")) Output of the above example: This is a fantastic day! [Try it yourself Β»](#) ## Example 2 Replace the letter "i" with "##": txt="This is a beautiful day!" document.write(Replace(txt,"i","##")) Output of the above example: Th##s ##s a beaut##ful day! [Try it yourself Β»](#) ## Example 3 Replace the letter "i" with "##", starting from position 15: Note that all characters before position 15 will be deleted. txt="This is a beautiful day!" document.write(Replace(txt,"i","##",15)) Output of the above example: t##ful day! [Try it yourself Β»](#) ## Example 4 Replace the first 2 occurrences of the letter "i" with "##", starting from position 1: txt="This is a beautiful day!" document.write(Replace(txt,"i","##",1,2)) Output of the above example: Th##s ##s a beautiful day! [Try it yourself Β»](#) ## Example 5 Replace the letter "t" with "##", using both textual and binary comparison: txt="This is a beautiful day!" document.write(Replace(txt,"t","##",1,-1,1) & "
") document.write(Replace(txt,"t","##",1,-1,0)) Output of the above example: ##his is a beau##iful day! This is a beau##iful day! [Try it yourself Β»](#) * * Complete VBScript Reference Manual](#)
← Func RightFunc Mid β†’