Some string functions

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 some string functions, maybe you find them
useful.

Greetings ..
Roxxler



Procedure.s ReverseStr(string$)
;string$ : string which will be reversed

If Len(string$)>1
For i.w=Len(string$) To 1 Step -1
dummy$+Mid(string$,i,1)
Next
string$=dummy$
dummy$=""
EndIf
ProcedureReturn string$
EndProcedure
a$="Amiga"
PrintN(a$)
a$=ReverseStr(a$)
PrintN(a$)
End

---

Procedure.s ReverseStrSpace(string$)
;string$ : string which will be reversed
; after every character (except the last one)
; a space will be inserted

If Len(string$)>1
For i.w=Len(string$) To 1 Step -1
dummy$+Mid(string$,i,1)+Chr(32)
Next
string$=StripTrail(dummy$)
dummy$=""
EndIf
ProcedureReturn string$
EndProcedure
a$="Amiga"
PrintN(a$)
a$=ReverseStrSpace(a$)
PrintN(a$)
End

---

Procedure.s SpacesStr(anzahlspaces.w)
; just create a string with the given number spaces

For z.w=1 to anzahlspaces
string$=string$+Chr(32)
Next
ProcedureReturn string$
EndProcedure
a$=""
PrintN(a$+"""
string$=StripLead(string$)
string$=StripTrail(string$)
pos.w=0
anzahl.w=0
Repeat
pos+1
anzahl+1
pos=FindString(string$," ",pos)
Until pos=0
Else
anzahl=0
EndIf
ProcedureReturn anzahl
EndProcedure
a$="This is just a test"
word.w=WordCountStr(a$)
PrintN("There are "+Str(word)+" words in the String:")
PrintN(a$)
End