REPLACE$ Function (VB work-a-like)

Modified on 2021/11/25 17:20 by CaptainBoing — Categorized as: Strings

Returns a string in which all occurrences of one specified substring have been replaced with another.

Syntax:
Replace$(expression, find, replacewith)

Example:
fred$=Replace$(Date$,"/","-") 'replaces all / in the date with -

Code:
	Function Replace$(a$,b$,c$)
		Local Integer z,d,e
		Local r$,x$
		z=1:d=Len(c$):e=Len(b$):r$=a$
		Do
			z=Instr(z,r$,b$)
			If z=0 Then Exit Do
			x$=Left$(r$,z-1)
			r$=x$+c$+Mid$(r$,z+e)
			z=Len(x$)+d
		Loop
		Replace$=r$
	End FunctionN