@ReplaceSubString als Funktion:
Function ReplaceSubString(SourceS As String, SearchS As String, ReplaceS As String) As String
While Instr(SourceS, SearchS) > 0
SourceS = Left$(SourceS, Instr(SourceS, SearchS) - 1) + ReplaceS + Right$(SourceS, Len(SourceS) - Instr(SourceS, SearchS) - Len(SearchS) + 1)
Wend
ReplaceSubstring = SourceS
End Function
Weiteres Beispiel als Funktion:
Function ReplaceSubstring(Byval s As String, target As String, replace As String) As String
Dim p As Integer
Dim length As Integer
Dim anchor As Integer
length = Len(target)
anchor = 1
Do
p = Instr(anchor, s, target)
If p = 0 Then
ReplaceSubstring = s
Exit Function
End If
s = Left$(s, p - 1) + replace + Mid$(s, p + length)
anchor = p + 1
Loop
End Function
Noch ein Beispiel:
Ersetzt jedes definierte Zeichen in einem String durch ein anderes definiertes Zeichen
Function changeStringcode(tochange As String,Removevalue As String, newvalue As String) As String
Dim leftpart As String
Dim rightpart As String
Dim PosOfChange As Integer
PosOfChange = Instr(tochange, Removevalue)
While PosOfChange > 0
Leftpart = Left$(toChange,posofchange-1)
rightpart = Right$(tochange,Len(tochange)-(Len(leftpart) +Len(removevalue)))
tochange = Leftpart + newvalue + Rightpart
PosOfChange = Instr(tochange, Removevalue)
Wend
changestringcode = tochange
End Function
Oder mit Evaluate:
eval = Evaluate(|@ReplaceSubstring(Name;"\'";"\'\'"|)