str replace function that works in fbs

FBS (freeBASIC script) is an interpreter for FbCadCam macros and a server side script engine.

Moderators: yajra1219, Jayem, kitty_webb, Ywsp, joanCruz03, shela

Post Reply
owen
Site Admin
Posts: 657
Joined: Thu Apr 13, 2017 12:14 pm

str replace function that works in fbs

Post by owen » Sat May 23, 2020 3:57 pm

Code: Select all

Declare Function str_replace(replace_this As String, with_this As String, in_this As String) As String

Function str_replace(replace_this As String, with_this As String, in_this As String) As String
	Dim As Integer x, lort
	Dim As String new_string
	lort = Len(replace_this)
	x = InStr(in_this, replace_this)
	Do While x <> 0
		new_string = Left(in_this, x-1)
		new_string += with_this
		in_this = new_string + Mid(in_this, x + lort)
		x = InStr(in_this, replace_this)
	Loop
	Return in_this
End Function
Dim As String a, b, c, r
a="a"
b="f"
c="abcabcabc"
r=str_replace(a,b,c)
Print r
Sleep
'returns fbcfbcfbc


Post Reply