Again some string procedures

AmigaOS specific forum
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Roxxler.

Hi,

here again some string functions. Maybe you can use them.


Procedure.s ReplaceStr(string$,suche$,ersatz$)
; string$= we search ins this string
; suche$ = we search this string
; ersatz$= if suche$ is found it will be replaced by this
; all suche$ will be replaced
If string$""
If FindString(string$,suche$,1)0
Repeat
pos.w=FindString(string$,suche$,1)
dummy$=Left(string$,pos-1)+ersatz$
dummy$=dummy$+Mid(string$,pos+Len(suche$),Len(string$)-pos+Len(suche$))
string$=dummy$
Until FindString(string$,suche$,1)=0
dummy$=""
EndIf
EndIf
ProcedureReturn string$
EndProcedure


Procedure.s ReplaceStrLeft(string$,suche$,ersatz$)
; string$= we search ins this string
; suche$ = we search this string
; ersatz$= if suche$ is found it will be replaced by this
; only the first from left founded suche$ will be replaced
If string$""
pos.w=FindString(string$,suche$,1)
If pos0
dummy$=Left(string$,pos-1)+ersatz$
dummy$=dummy$+Mid(string$,pos+Len(suche$),Len(string$)-pos+Len(suche$))
string$=dummy$
dummy$=""
EndIf
EndIf
ProcedureReturn string$
EndProcedure


Procedure.s ReplaceStrRight(string$,suche$,ersatz$)
; string$= we search ins this string
; suche$ = we search this string
; ersatz$= if suche$ is found it will be replaced by this
; only the first from right founded suche$ will be replaced
If string$""
pos.w=FindString(string$,suche$,1)
If pos0
start.w=1
Repeat
pos=FindString(string$,suche$,start)
start=pos+1
Until FindString(string$,suche$,start)=0
dummy$=Left(string$,pos-1)+ersatz$
dummy$=dummy$+Mid(string$,pos+Len(suche$),Len(string$)-pos+Len(suche$))
string$=dummy$
dummy$=""
EndIf
EndIf
ProcedureReturn string$
EndProcedure


Greetings ..
Roxxler