User Tools

Site Tools


mmbasic:vb_work_a_like_replace_function

REPLACE$ Function (VB work-a-like)

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 Function
mmbasic/vb_work_a_like_replace_function.txt · Last modified: 2024/01/19 09:30 by 127.0.0.1