In der Regel nimmt man dazu ReplaceString.
Für bestimmte Anwendungen könnte es sich aber zeitlich lohnen eine schnellere Variante zu benutzen.
Hier mal eigene Varianten im Vergleich zur schnellsten ReplaceString Methode.
Debugger ausschalten !!!
Code: Alles auswählen
Structure Format1
StructureUnion
s.s{20}
c.c[0]
EndStructureUnion
EndStructure
Procedure myReplace(*x.Format1)
For i = 0 To SizeOf(Format1)-1
If *x\c[i] = 44 ;komma
*x\c[i] = 46 ;punkt
Break
EndIf
Next
EndProcedure
Procedure myReplace1(*x.Format1, such, ersatz)
For i = 0 To SizeOf(Format1)-1
If *x\c[i] = such
*x\c[i] = ersatz
EndIf
Next
EndProcedure
Procedure.s myReplace2(*x.Format1, such, ersatz)
For i = 0 To SizeOf(Format1)-1
If *x\c[i] = such
*x\c[i] = ersatz
EndIf
Next
ProcedureReturn *x\s
EndProcedure
;==========================
z.Format1
max = 500000
;==========================
a=GetTickCount_()
For j = 1 To max
z\s = "12345,78"
For i = 0 To SizeOf(Format1)-1
If z\c[i] = 44 ;komma
z\c[i] = 46 ;punkt
Break
EndIf
Next
Next
Debug RSet(z\s,SizeOf(Format1))
o=GetTickCount_()-a
;==========================
a=GetTickCount_()
For j = 1 To max
z\s = "12345,78"
myReplace(z)
Next
Debug RSet(z\s,SizeOf(Format1))
q=GetTickCount_()-a
;==========================
a=GetTickCount_()
For j = 1 To max
z\s = "12345,78"
myReplace1(z, ',', '.')
Next
Debug RSet(z\s,SizeOf(Format1))
b=GetTickCount_()-a
;==========================
a=GetTickCount_()
For j = 1 To max
z\s = "12345,78"
z\s = myReplace2(z, ',', '.')
Next
Debug RSet(z\s,SizeOf(Format1))
c=GetTickCount_()-a
;==========================
a=GetTickCount_()
For j = 1 To max
x$ = "12345,78"
ReplaceString(x$, ",", ".", 2)
Next
Debug RSet(x$,SizeOf(Format1))
d=GetTickCount_()-a
MessageRequester("",Str(o)+#LF$+Str(q)+#LF$+Str(b)+#LF$+Str(c)+#LF$+Str(d))
PS: Das Prinzip funktioniert auch mit CountString