Hi.
I made some IMHO usefull functions for string-management.
I know, most of them are not really big, complicated or rare, and nearly everyone could programm most of them himself, but this is a relative big collection of functions with documentation.
Here the command-list with small description: (copy of the help-file)
String-Commands:
ms_MidWord$(Source$,Position,Length) – Returns the selected string-part
ms_AddWord$(Source$,Position,Word$) – Adds ‘word$’ to the string, into the selected position
ms_DeleteMid$(Source$,Position) – Deletes the selected character of the string
ms_DeleteWord$(Source$,Position,Length) – Deletes the selected stringpart
ms_WordCount(Source$,String$) – Returns a value, which describes how often ‘string$’ is included in the ‘source$’
ms_ReplaceWord$(Source$,Position,Length,Replace$) – Deletes the selected string-part and inserts ‘replace$’
ms_ReplaceMid$(Source$,Position,New$) – Replaces a character with ‘new$’
ms_ReplaceWords$(Source$,Delete$,Insert$) – Deletes all ‘delete$’ in ‘source$’ and inserts ‘insert$’ at this positions
ms_DeleteWords$(Source$,Delete$) – Deletes all ‘delete$’ in ‘source$’
ms_Mirror$(String$) – Mirrors ‘string$’ so that the first character is at the last position
ms_MirrorCase$(String$) – Mirrors all cases, so that small characters become big ones
ms_FirstBig$(String$) – Returns ‘string$’ in lowercase with the first character being big
ms_ASCSum(String$) – Returns the ASCII-sum of ‘string$’
ms_Cases(String$,CaseType) – Returns the number of characters in low or high case. The case depends on ‘casetype’ (0=low; 1=high)
ms_Sort$(Source$) – Sorts the string-characters
ms_StringPosition(Source$,String$) – Returns the position of ‘string$’ in ‘source$’ or 0
ms_WordExist(Source$,String$) – Returns a 1 if ‘string$’ is a part of ‘source$’
ms_First_Token$(Source$,Sign$) – Returns the first part of ‘source$’ up to the first ‘sign$’
ms_Next_Token$() – Returns the next string-part
ms_Split_String(Source$,Split$,BrStart$,BrEnd$,Quote$) – Splits ‘source’ at each ‘split$’ which is not placed in brackets or quotation-signs. The String-parts are saved into the array ‘ms_StringPart$()’ and the number of parts is returned and also saved into the variable ‘ms_SplitString_Count’
ms_ShuffleWord$(Source$) – Switches the positions of the letters in ‘source$’
ms_CharTypeCount(Source$,CharType) – Returns, how much vocals or consonants are included in ‘source$’. If ‘chartype’ is 1, the functions counts the vocals.
ms_ShuffleCase$(Source$) – Shuffles the cases of ‘source$’, the number of high and low-cases stays as it was before.
ms_RandomCase$(Source$) – The cases of ‘source$’ are randomly resetted
ms_CompareString(String1$,String2$) – Returns, which string is alphabetically before the other, or a 0 if they are similar
List-Commands:
ms_ResetList(MaxElements) – Resets the list and defines, what is the maximum number of list-elements, you have to call this command before you use a new list
ms_AddListItem(String$) – Adds an item to the list
ms_RemoveListItem(Position) – Removes the list-item from the selected position
ms_ShuffleList() – Shuffles the list-item-order
ms_SortList() – Sorts the list alphabetically
ms_MirrorList() – Mirrors the list-items, so that the first elements becomes the last one
ms_ListString$(Position) – Returns the list-item of the selected position
ms_TotalListItems() – Returns, how much items are added to the list
ms_MaxListItems() – Returns the maximum item-number
ms_PrintList() – Prints all list-items to the screen
What are the functions good for?
1. String-functions
You can use them for some more or less usefull actions like inserting strings into others, comparing them (returns, which one would be higher in the alphabet), sorting them character by character, mirroring them, or letting just all words of one kind be deleted.
2. List-functions
You can setup a list and add items (strings), then you can let the list be shuffled, sorted or mirrored, and then read all items out of it.
Here is the full code with example and functions:
REM **Example-Code**
set display mode 1024,768,32
set text font "Arial"
set text size 14
randomize timer()
cls
String$ = "This is a string"
print String$
wait key
print
Part$ = ms_MidWord$(String$, 6, 2)
print "Part 2: ", Part$
wait key
print
Add$ = ms_AddWord$(String$, 7, " not")
print "Added: ", Add$
wait key
print
Del$ = ms_DeleteMid$(String$, 9)
print "Deleted: ", Del$
wait key
print
Del$ = ms_deleteWord$(String$, 9, 2)
print "Deleted2: ", Del$
wait key
print
String2$ = "This is a string, and this string is a very cool string, and includes the word 'string' about 4 times."
C = ms_WordCount(String2$, "string")
print "String2: ", String2$
print "Number of 'string's: ", C
wait key
print
String$ = "This is a string"
Re$ = ms_ReplaceWord$(String$, 11, 6, "sentence")
print "Replaced: ", Re$
wait key
print
Re2$ = ms_ReplaceMid$(String$, 9, "1")
print "Replaced2: ", Re2$
wait key
print
Re3$ = ms_ReplaceWords$(String2$, "string", "*BEEP*")
print "Replaced3: ", Re3$
wait key
print
input "Insert a string>", User$
User$ = upper$(User$)
Leet$ = ms_ReplaceWords$(User$, "E", "3")
Leet$ = ms_ReplaceWords$(Leet$, "A", "4")
Leet$ = ms_ReplaceWords$(Leet$, "H", "]-[")
Leet$ = ms_ReplaceWords$(Leet$, "B", "8")
Leet$ = ms_ReplaceWords$(Leet$, "V", "\/")
Leet$ = ms_ReplaceWords$(Leet$, "N", "|\|")
Leet$ = ms_ReplaceWords$(Leet$, "M", "|V|")
Leet$ = ms_ReplaceWords$(Leet$, "I", "!")
Leet$ = ms_ReplaceWords$(Leet$, "O", "0")
Leet$ = ms_ReplaceWords$(Leet$, "S", "$")
Leet$ = ms_ReplaceWords$(Leet$, "T", "'|'")
print "Alternative: ", Leet$
Del$ = ms_DeleteWords$(String2$, "string")
wait key
print
print "Deleted: ", Del$
wait key
print
Mir$ = ms_Mirror$(String$)
print "Mirrored: ", Mir$
wait key
print
String3$ = "Peter is a friend of Horst and likes playing FEAR."
CMir$ = ms_MirrorCase$(String3$)
print "String3: ", String3$
print "Case-Mirrored: ", CMir$
wait key
print
cls
Word$ = "pEteR"
Big$ = ms_FirstBig$(Word$)
print "Word: ", Word$
print "First big: ", Big$
wait key
print
_ASC = ms_ASCSum(Big$)
print "ASCII-Sum of '",Big$,"': ", _ASC
wait key
print
Word2$ = "FEAR is a game with four capitols."
Cap = ms_Cases(Word2$,1)
print "Word2: ", Word2$
print "Capitols: ", Cap
wait key
print
String4$ = "hbdsfaljviehwvnbuzefadjfi"
Sort$ = ms_Sort$(String4$)
print "String4: ", String4$
print "Sorted: ", Sort$
wait key
print
String5$ = "Command Value1,Value2,Value3,Value4"
print "Code-Line: ",String5$
String5$ = ms_ReplaceWords$(String5$,","," ")
Num = ms_WordCount(String5$," ")-1
Com$ = ms_First_Token$(String5$," ")
print "Command: ", com$
for P = 1 to Num
print "Parameter ",P,": ", ms_Next_Token$()
next P
wait key
print
cls
String6$ = "This.is.a.sentence.seperated.by.points.(with.brackets.at.the.end).except.the.'last.three.words.'"
Parts = ms_Split_String(String6$,".","(",")","'")
print "String6: ", String6$
print "Parts: ", Parts
for P = 1 to Parts
print "Part ",P,": ", ms_StringPart$(P)
next P
wait key
print
String$ = "This is a string."
print "String1: ", String$
nosign$ = ms_DeleteWords$(String$,".")
nosign$ = ms_DeleteWords$(nosign$," ")
print "Without signs: ", nosign$
shuf$ = ms_ShuffleWord$(nosign$)
print "Shuffled: ", shuf$
wait key
print
input "Insert your name>",name$
v = ms_CharTypeCount(name$,1)
c = ms_CharTypeCount(name$,0)
print "Your name includes ", v, " vocals and ",c," consonants."
wait key
print
shuf2$ = ms_ShuffleCase$(name$)
print "Your name with shuffled cases: ", shuf2$
wait key
print
shuf3$ = ms_RandomCase$(name$)
print "Your name with random cases: ", shuf3$
wait key
print
cls
REM List-Commands
print "Installing the list..."
ms_ResetList(10)
ms_AddListItem("Peter")
ms_AddListItem("Horst")
ms_AddListItem("Roland")
ms_AddListItem("Dieter")
ms_AddListItem("Juergen")
ms_AddListItem("Guenther")
ms_AddListItem("Jonathan")
ms_AddListItem("Siegfried")
ms_AddListItem("Hans")
ms_AddListItem("Ullrich")
ms_PrintList()
print
print "Shuffling list..."
ms_ShuffleList()
print "Press any key!"
wait key
ms_PrintList()
wait key
cls
print "Sorting List..."
ms_SortList()
ms_PrintList()
print
print "Mirroring List..."
ms_MirrorList()
print "Press any key!"
wait key
ms_PrintList()
wait key
end
REM **Example-End**
REM Modern Strings
REM by Modern Productions
REM 09.10.06
REM You may use this functions in your applications/games if you want,
REM and you may also write us to the credits, if you want. ;-)
REM *************************************************************************
function ms_MidWord$(Source$, Position, Length)
dec Position
Word$ = left$( right$( Source$,len(Source$)-Position),Length )
endfunction Word$
REM *************************************************************************
REM *************************************************************************
function ms_AddWord$(Source$, Position, Word$)
NewWord$ = left$(Source$, Position) + Word$ + right$(Source$, len(Source$)-Position)
endfunction NewWord$
REM *************************************************************************
REM *************************************************************************
function ms_DeleteMid$(Source$, Position)
NewWord$ = left$(Source$, Position-1) + right$(Source$, len(Source$)-Position)
endfunction NewWord$
REM *************************************************************************
REM *************************************************************************
function ms_DeleteWord$(Source$, Position, Length)
NewWord$ = left$(Source$, Position-1) + right$(Source$, len(Source$) - Position - Length + 1)
endfunction NewWord$
REM *************************************************************************
REM *************************************************************************
function ms_WordCount(Source$, String$)
Length = len(String$)
Target = len(Source$)-Length+1
Count = 0
for Z = 1 to Target
if ms_MidWord$(Source$, Z, Length) = String$ then inc Count
next Z
endfunction Count
REM *************************************************************************
REM *************************************************************************
function ms_ReplaceWord$(Source$, Position, Length, Replace$)
NewWord$ = left$(Source$, Position-1) + Replace$ + right$(Source$, len(Source$) - Position - Length +1)
endfunction NewWord$
REM *************************************************************************
REM *************************************************************************
function ms_ReplaceMid$(Source$, Position, New$)
NewWord$ = left$(Source$, Position-1) + New$ + right$(Source$, len(Source$) - Position)
endfunction NewWord$
REM *************************************************************************
REM *************************************************************************
function ms_ReplaceWords$(Source$, Old$, New$)
Length = len(Old$)
Target = len(Source$)-Length+1
Dif = len(Old$) - len(New$)
for Z = 1 to Target
if ms_MidWord$(Source$, Z, Length) = Old$
dec Target, Dif
Source$ = left$(Source$, Z-1) + New$ + right$(Source$, len(Source$) - Z - Length+1)
endif
next Z
endfunction Source$
REM *************************************************************************
REM *************************************************************************
function ms_DeleteWords$(Source$, Delete$)
Length = len(Delete$)
Target = len(Source$)-Length+1
for Z = 1 to Target
if ms_MidWord$(Source$, Z, Length) = Delete$
dec Target, Length
Source$ = left$(Source$, Z-1) + right$(Source$, len(Source$) - Z - Length+1)
endif
next Z
endfunction Source$
REM *************************************************************************
REM *************************************************************************
function ms_Mirror$(String$)
Target = len(String$)
for Z = 1 to Target
NewString$ = mid$(String$,Z) + NewString$
next Z
endfunction NewString$
REM *************************************************************************
REM *************************************************************************
function ms_MirrorCase$(String$)
Target = len(String$)
for Z = 1 to Target
m$ = mid$(String$,Z)
if m$ = lower$(m$)
NewString$ = NewString$ + upper$(m$)
else
NewString$ = NewString$ + lower$(m$)
endif
next Z
endfunction NewString$
REM *************************************************************************
REM *************************************************************************
function ms_FirstBig$(String$)
NewString$ = upper$(Left$(String$,1)) + lower$(Right$(String$, len(String$)-1))
endfunction NewString$
REM *************************************************************************
REM *************************************************************************
function ms_ASCSum(String$)
Target = len(String$)
for Z = 1 to Target
inc Value, asc(mid$(String$,Z))
next Z
endfunction Value
REM *************************************************************************
REM *************************************************************************
function ms_Cases(String$, CaseType as boolean)
Target = len(String$)
CaseCount = 0
for Z = 1 to Target
M$ = mid$(String$,Z)
if CaseType=0
if M$ = lower$(M$) and M$ <> upper$(M$)
inc CaseCount
endif
else
if M$ = upper$(M$) and M$ <> lower$(M$)
inc CaseCount
endif
endif
next Z
endfunction CaseCount
REM *************************************************************************
REM *************************************************************************
function ms_Sort$(Source$)
Target = len(Source$)
NewString$ = ""
for Z = 1 to Target
M$ = mid$(Source$, Z)
Length = len(NewString$)
if Length = 0
NewString$ = M$
else
Added = 0
for Z2 = 1 to Length
if asc(M$) < asc(mid$(NewString$, Z2)) and Added = 0
NewString$ = left$(NewString$, Z2-1) + M$ + right$(NewString$, len(NewString$)-Z2+1)
Added = 1
endif
next Z2
if Added = 0 then NewString$ = NewString$ + M$
endif
next Z
endfunction NewString$
REM *************************************************************************
REM *************************************************************************
function ms_StringPosition(Source$, String$)
Length = len(String$)
Target = len(Source$)-Length+1
for Z = 1 to Target
if ms_MidWord$(Source$, Z, Length) = String$ then exitfunction Z
next Z
endfunction 0
REM *************************************************************************
REM *************************************************************************
function ms_WordExist(Source$, Part$)
Length = len(String$)
Target = len(Source$)-Length+1
for Z = 1 to Target
if ms_MidWord$(Source$, Z, Length) = String$ then exitfunction 1
next Z
endfunction 0
REM *************************************************************************
REM *************************************************************************
function ms_First_Token$(Source$, Sign$)
global ms_TokenString$
global ms_TokenSign$ = Sign$
Target = len(Source$)
StringPart$ = Source$
for Z = 1 to Target
if mid$(Source$,Z)=Sign$
StringPart$ = left$(Source$,Z-1)
ms_TokenString$ = right$(Source$, Target-Z)
exitfunction StringPart$
endif
next Z
endfunction Source$
REM *************************************************************************
REM *************************************************************************
function ms_Next_Token$()
Source$ = ms_TokenString$
Sign$ = ms_TokenSign$
Target = len(Source$)
StringPart$ = Source$
for Z = 1 to Target
if mid$(Source$,Z)=Sign$
StringPart$ = left$(Source$,Z-1)
ms_TokenString$ = right$(Source$, Target-Z)
exitfunction StringPart$
endif
next Z
endfunction Source$
REM *************************************************************************
REM *************************************************************************
function ms_Split_String(Source$,Seperate$,BrStart$,BrEnd$,Quote$)
Target = len(Source$)
`BracketsActive as boolean
BracketsActive = 0
QuoteActive as boolean
Number = (Target>0)
for Z = 1 to Target
m$ = mid$(Source$,Z)
if m$ = Seperate$ and BracketsActive=0 and QuoteActive=0 then inc Number
if m$ = BrStart$ then inc BracketsActive
if m$ = BrEnd$ then dec BracketsActive
if m$ = Quote$ then QuoteActive = QuoteActive-1
next Z
global ms_SplitString_Count = Number
dim ms_StringPart$(Number)
ActString$ = ""
ActPos = 0
BracketsActive=0
QuoteActive=0
if right$(Source$,1)<>Seperate$
Source$ = Source$ + Seperate$
inc Target,1
endif
for Z = 1 to Target
m$ = mid$(Source$,Z)
if m$ = BrStart$ then inc BracketsActive
if m$ = BrEnd$ then dec BracketsActive
if m$ = Quote$ then QuoteActive = 1-QuoteActive
if (m$ <> Seperate$) or (BracketsActive+QuoteActive>0)
ActString$ = ActString$ + m$
endif
if (BracketsActive=0 and QuoteActive=0)
if m$ = Seperate$
inc ActPos
ms_StringPart$(ActPos)=ActString$
ActString$ = ""
endif
endif
next Z
endfunction Number
REM *************************************************************************
REM *************************************************************************
function ms_ShuffleWord$(Source$)
Target = len(Source$)
dim ms_Temp_Char$(Target-1)
for Z = 1 to Target
ms_Temp_Char$(Z-1) = mid$(Source$,Z)
next Z
Length = Target-1
for Z = 1 to Target
pos = rnd(Length)
dec Length
m$ = ms_Temp_Char$(pos)
array delete element ms_Temp_Char$(0), pos
String$ = String$ + m$
next Z
undim ms_Temp_Char$(0)
endfunction String$
REM *************************************************************************
REM *************************************************************************
function ms_CharTypeCount(Source$, CharType)
Count = 0
Target = len(Source$)
Source$ = lower$(Source$)
for Z = 1 to Target
m$ = mid$(Source$,Z)
if (m$="a" or m$="e" or m$="i" or m$="o" or m$="u")=CharType
inc Count
endif
next Z
endfunction Count
REM *************************************************************************
REM *************************************************************************
function ms_ShuffleCase$(Source$)
Target = len(Source$)
High = ms_Cases(Source$,1)
Source$ = lower$(Source$)
for X = 1 to High
repeat
pos = rnd(Target)
m$ = mid$(Source$,pos)
until m$<>upper$(m$)
Source$ = ms_ReplaceMid$(Source$,pos,upper$(m$))
next X
endfunction Source$
REM *************************************************************************
REM *************************************************************************
function ms_RandomCase$(Source$)
Target = len(Source$)
for Z = 1 to Target
m$ = mid$(Source$,Z)
C = rnd(1)
if C = 0
m$ = lower$(m$)
else
m$ = upper$(m$)
endif
String$ = String$ + m$
next Z
endfunction String$
REM *************************************************************************
REM *************************************************************************
function ms_CompareString(String1$, String2$)
S1$ = lower$(String1$)
S2$ = lower$(String2$)
Target1 = len(S1$)
Target2 = len(S2$)
if Target1 > Target2
Target = Target2
else
Target = Target1
endif
for Z = 1 to target
m1$ = mid$(S1$,Z)
m2$ = mid$(S2$,Z)
m1 = asc(m1$)
m2 = asc(m2$)
if m1>m2
exitfunction 2
else
if m2>m1 then exitfunction 1
endif
next Z
if Target1 > Target2
exitfunction 2
else
exitfunction 1
endif
endfunction 0
REM *************************************************************************
REM *************************************************************************
function ms_ResetList(MaxElements)
global ms_List_MaxElements = MaxElements
global ms_List_ActPos : ms_List_ActPos = 0
dim ms_ListItem$(MaxElements)
endfunction
REM *************************************************************************
REM *************************************************************************
function ms_AddListItem(String$)
inc ms_List_ActPos
ms_ListItem$(ms_List_ActPos) = String$
endfunction
REM *************************************************************************
REM *************************************************************************
function ms_RemoveListItem(Position)
dec ms_List_ActPos
for Z = ms_List_ActPos to Position step -1
ms_ListItem$(Z)=ms_ListItem$(Z+1)
next Z
endfunction
REM *************************************************************************
REM *************************************************************************
function ms_ShuffleList()
dim ms_Temp_Item$(ms_List_ActPos)
for X = 1 to ms_List_ActPos
ms_Temp_item$(X) = ms_ListItem$(X)
next X
ms_TempPos = ms_List_ActPos-1
for X = 1 to ms_List_ActPos
pos = 1+rnd(ms_TempPos)
dec ms_TempPos, 1
ms_ListItem$(X)=ms_Temp_Item$(pos)
array delete element ms_Temp_Item$(0), pos
next X
undim ms_Temp_Item$(0)
endfunction
REM *************************************************************************
REM *************************************************************************
function ms_SortList()
dim ms_Temp_Item$(ms_List_ActPos)
local Actpos : Actpos = 0
V$ = chr$(255)
for X = 1 to ms_List_ActPos
ms_Temp_item$(X)=V$
next X
for X = 1 to ms_List_ActPos
m$ = ms_ListItem$(X)
changed=0
for Pos = 1 to ms_List_ActPos
m2$ = ms_Temp_Item$(Pos)
c = ms_CompareString(m$,m2$)
if c=1
changed = 1
inc actpos
for Pos2 = ms_List_ActPos to Pos+1 step -1
ms_Temp_item$(Pos2)=ms_Temp_item$(Pos2-1)
next Pos2
ms_Temp_Item$(Pos) = m$
exit
endif
next Pos
if changed = 0
inc Actpos
ms_Temp_item$(Actpos) = m$
endif
next X
for X = 1 to ms_List_ActPos
ms_ListItem$(X) = ms_Temp_Item$(X)
next X
undim ms_Temp_Item$(0)
endfunction
REM *************************************************************************
REM *************************************************************************
function ms_MirrorList()
dim ms_Temp_Item$(ms_List_ActPos)
for X = 1 to ms_List_ActPos
ms_Temp_item$(X)=ms_ListItem$(X)
next X
for X = 1 to ms_List_ActPos
ms_ListItem$(X) = ms_Temp_item$(ms_List_ActPos-X+1)
next X
endfunction
REM *************************************************************************
REM *************************************************************************
function ms_ListString$(Position)
String$ = ms_ListItem$(Position)
endfunction String$
REM *************************************************************************
REM *************************************************************************
function ms_TotalListItems()
endfunction ms_List_ActPos
REM *************************************************************************
REM *************************************************************************
function ms_MaxListItems()
endfunction ms_List_MaxElements
REM *************************************************************************
REM *************************************************************************
function ms_PrintList()
for X = 1 to ms_List_ActPos
print "List Element "+str$(X)+": "+ms_ListItem$(X)
next X
endfunction
REM *************************************************************************
And here are just the functions: (both included in the attached rar-file)
REM *************************************************************************
function ms_MidWord$(Source$, Position, Length)
dec Position
Word$ = left$( right$( Source$,len(Source$)-Position),Length )
endfunction Word$
REM *************************************************************************
REM *************************************************************************
function ms_AddWord$(Source$, Position, Word$)
NewWord$ = left$(Source$, Position) + Word$ + right$(Source$, len(Source$)-Position)
endfunction NewWord$
REM *************************************************************************
REM *************************************************************************
function ms_DeleteMid$(Source$, Position)
NewWord$ = left$(Source$, Position-1) + right$(Source$, len(Source$)-Position)
endfunction NewWord$
REM *************************************************************************
REM *************************************************************************
function ms_DeleteWord$(Source$, Position, Length)
NewWord$ = left$(Source$, Position-1) + right$(Source$, len(Source$) - Position - Length + 1)
endfunction NewWord$
REM *************************************************************************
REM *************************************************************************
function ms_WordCount(Source$, String$)
Length = len(String$)
Target = len(Source$)-Length+1
Count = 0
for Z = 1 to Target
if ms_MidWord$(Source$, Z, Length) = String$ then inc Count
next Z
endfunction Count
REM *************************************************************************
REM *************************************************************************
function ms_ReplaceWord$(Source$, Position, Length, Replace$)
NewWord$ = left$(Source$, Position-1) + Replace$ + right$(Source$, len(Source$) - Position - Length +1)
endfunction NewWord$
REM *************************************************************************
REM *************************************************************************
function ms_ReplaceMid$(Source$, Position, New$)
NewWord$ = left$(Source$, Position-1) + New$ + right$(Source$, len(Source$) - Position)
endfunction NewWord$
REM *************************************************************************
REM *************************************************************************
function ms_ReplaceWords$(Source$, Old$, New$)
Length = len(Old$)
Target = len(Source$)-Length+1
Dif = len(Old$) - len(New$)
for Z = 1 to Target
if ms_MidWord$(Source$, Z, Length) = Old$
dec Target, Dif
Source$ = left$(Source$, Z-1) + New$ + right$(Source$, len(Source$) - Z - Length+1)
endif
next Z
endfunction Source$
REM *************************************************************************
REM *************************************************************************
function ms_DeleteWords$(Source$, Delete$)
Length = len(Delete$)
Target = len(Source$)-Length+1
for Z = 1 to Target
if ms_MidWord$(Source$, Z, Length) = Delete$
dec Target, Length
Source$ = left$(Source$, Z-1) + right$(Source$, len(Source$) - Z - Length+1)
endif
next Z
endfunction Source$
REM *************************************************************************
REM *************************************************************************
function ms_Mirror$(String$)
Target = len(String$)
for Z = 1 to Target
NewString$ = mid$(String$,Z) + NewString$
next Z
endfunction NewString$
REM *************************************************************************
REM *************************************************************************
function ms_MirrorCase$(String$)
Target = len(String$)
for Z = 1 to Target
m$ = mid$(String$,Z)
if m$ = lower$(m$)
NewString$ = NewString$ + upper$(m$)
else
NewString$ = NewString$ + lower$(m$)
endif
next Z
endfunction NewString$
REM *************************************************************************
REM *************************************************************************
function ms_FirstBig$(String$)
NewString$ = upper$(Left$(String$,1)) + lower$(Right$(String$, len(String$)-1))
endfunction NewString$
REM *************************************************************************
REM *************************************************************************
function ms_ASCSum(String$)
Target = len(String$)
for Z = 1 to Target
inc Value, asc(mid$(String$,Z))
next Z
endfunction Value
REM *************************************************************************
REM *************************************************************************
function ms_Cases(String$, CaseType as boolean)
Target = len(String$)
CaseCount = 0
for Z = 1 to Target
M$ = mid$(String$,Z)
if CaseType=0
if M$ = lower$(M$) and M$ <> upper$(M$)
inc CaseCount
endif
else
if M$ = upper$(M$) and M$ <> lower$(M$)
inc CaseCount
endif
endif
next Z
endfunction CaseCount
REM *************************************************************************
REM *************************************************************************
function ms_Sort$(Source$)
Target = len(Source$)
NewString$ = ""
for Z = 1 to Target
M$ = mid$(Source$, Z)
Length = len(NewString$)
if Length = 0
NewString$ = M$
else
Added = 0
for Z2 = 1 to Length
if asc(M$) < asc(mid$(NewString$, Z2)) and Added = 0
NewString$ = left$(NewString$, Z2-1) + M$ + right$(NewString$, len(NewString$)-Z2+1)
Added = 1
endif
next Z2
if Added = 0 then NewString$ = NewString$ + M$
endif
next Z
endfunction NewString$
REM *************************************************************************
REM *************************************************************************
function ms_StringPosition(Source$, String$)
Length = len(String$)
Target = len(Source$)-Length+1
for Z = 1 to Target
if ms_MidWord$(Source$, Z, Length) = String$ then exitfunction Z
next Z
endfunction 0
REM *************************************************************************
REM *************************************************************************
function ms_WordExist(Source$, Part$)
Length = len(String$)
Target = len(Source$)-Length+1
for Z = 1 to Target
if ms_MidWord$(Source$, Z, Length) = String$ then exitfunction 1
next Z
endfunction 0
REM *************************************************************************
REM *************************************************************************
function ms_First_Token$(Source$, Sign$)
global ms_TokenString$
global ms_TokenSign$ = Sign$
Target = len(Source$)
StringPart$ = Source$
for Z = 1 to Target
if mid$(Source$,Z)=Sign$
StringPart$ = left$(Source$,Z-1)
ms_TokenString$ = right$(Source$, Target-Z)
exitfunction StringPart$
endif
next Z
endfunction Source$
REM *************************************************************************
REM *************************************************************************
function ms_Next_Token$()
Source$ = ms_TokenString$
Sign$ = ms_TokenSign$
Target = len(Source$)
StringPart$ = Source$
for Z = 1 to Target
if mid$(Source$,Z)=Sign$
StringPart$ = left$(Source$,Z-1)
ms_TokenString$ = right$(Source$, Target-Z)
exitfunction StringPart$
endif
next Z
endfunction Source$
REM *************************************************************************
REM *************************************************************************
function ms_Split_String(Source$,Seperate$,BrStart$,BrEnd$,Quote$)
Target = len(Source$)
`BracketsActive as boolean
BracketsActive = 0
QuoteActive as boolean
Number = (Target>0)
for Z = 1 to Target
m$ = mid$(Source$,Z)
if m$ = Seperate$ and BracketsActive=0 and QuoteActive=0 then inc Number
if m$ = BrStart$ then inc BracketsActive
if m$ = BrEnd$ then dec BracketsActive
if m$ = Quote$ then QuoteActive = QuoteActive-1
next Z
global ms_SplitString_Count = Number
dim ms_StringPart$(Number)
ActString$ = ""
ActPos = 0
BracketsActive=0
QuoteActive=0
if right$(Source$,1)<>Seperate$
Source$ = Source$ + Seperate$
inc Target,1
endif
for Z = 1 to Target
m$ = mid$(Source$,Z)
if m$ = BrStart$ then inc BracketsActive
if m$ = BrEnd$ then dec BracketsActive
if m$ = Quote$ then QuoteActive = 1-QuoteActive
if (m$ <> Seperate$) or (BracketsActive+QuoteActive>0)
ActString$ = ActString$ + m$
endif
if (BracketsActive=0 and QuoteActive=0)
if m$ = Seperate$
inc ActPos
ms_StringPart$(ActPos)=ActString$
ActString$ = ""
endif
endif
next Z
endfunction Number
REM *************************************************************************
REM *************************************************************************
function ms_ShuffleWord$(Source$)
Target = len(Source$)
dim ms_Temp_Char$(Target-1)
for Z = 1 to Target
ms_Temp_Char$(Z-1) = mid$(Source$,Z)
next Z
Length = Target-1
for Z = 1 to Target
pos = rnd(Length)
dec Length
m$ = ms_Temp_Char$(pos)
array delete element ms_Temp_Char$(0), pos
String$ = String$ + m$
next Z
undim ms_Temp_Char$(0)
endfunction String$
REM *************************************************************************
REM *************************************************************************
function ms_CharTypeCount(Source$, CharType)
Count = 0
Target = len(Source$)
Source$ = lower$(Source$)
for Z = 1 to Target
m$ = mid$(Source$,Z)
if (m$="a" or m$="e" or m$="i" or m$="o" or m$="u")=CharType
inc Count
endif
next Z
endfunction Count
REM *************************************************************************
REM *************************************************************************
function ms_ShuffleCase$(Source$)
Target = len(Source$)
High = ms_Cases(Source$,1)
Source$ = lower$(Source$)
for X = 1 to High
repeat
pos = rnd(Target)
m$ = mid$(Source$,pos)
until m$<>upper$(m$)
Source$ = ms_ReplaceMid$(Source$,pos,upper$(m$))
next X
endfunction Source$
REM *************************************************************************
REM *************************************************************************
function ms_RandomCase$(Source$)
Target = len(Source$)
for Z = 1 to Target
m$ = mid$(Source$,Z)
C = rnd(1)
if C = 0
m$ = lower$(m$)
else
m$ = upper$(m$)
endif
String$ = String$ + m$
next Z
endfunction String$
REM *************************************************************************
REM *************************************************************************
function ms_CompareString(String1$, String2$)
S1$ = lower$(String1$)
S2$ = lower$(String2$)
Target1 = len(S1$)
Target2 = len(S2$)
if Target1 > Target2
Target = Target2
else
Target = Target1
endif
for Z = 1 to target
m1$ = mid$(S1$,Z)
m2$ = mid$(S2$,Z)
m1 = asc(m1$)
m2 = asc(m2$)
if m1>m2
exitfunction 2
else
if m2>m1 then exitfunction 1
endif
next Z
if Target1 > Target2
exitfunction 2
else
exitfunction 1
endif
endfunction 0
REM *************************************************************************
REM *************************************************************************
function ms_ResetList(MaxElements)
global ms_List_MaxElements = MaxElements
global ms_List_ActPos : ms_List_ActPos = 0
dim ms_ListItem$(MaxElements)
endfunction
REM *************************************************************************
REM *************************************************************************
function ms_AddListItem(String$)
inc ms_List_ActPos
ms_ListItem$(ms_List_ActPos) = String$
endfunction
REM *************************************************************************
REM *************************************************************************
function ms_RemoveListItem(Position)
dec ms_List_ActPos
for Z = ms_List_ActPos to Position step -1
ms_ListItem$(Z)=ms_ListItem$(Z+1)
next Z
endfunction
REM *************************************************************************
REM *************************************************************************
function ms_ShuffleList()
dim ms_Temp_Item$(ms_List_ActPos)
for X = 1 to ms_List_ActPos
ms_Temp_item$(X) = ms_ListItem$(X)
next X
ms_TempPos = ms_List_ActPos-1
for X = 1 to ms_List_ActPos
pos = 1+rnd(ms_TempPos)
dec ms_TempPos, 1
ms_ListItem$(X)=ms_Temp_Item$(pos)
array delete element ms_Temp_Item$(0), pos
next X
undim ms_Temp_Item$(0)
endfunction
REM *************************************************************************
REM *************************************************************************
function ms_SortList()
dim ms_Temp_Item$(ms_List_ActPos)
local Actpos : Actpos = 0
V$ = chr$(255)
for X = 1 to ms_List_ActPos
ms_Temp_item$(X)=V$
next X
for X = 1 to ms_List_ActPos
m$ = ms_ListItem$(X)
changed=0
for Pos = 1 to ms_List_ActPos
m2$ = ms_Temp_Item$(Pos)
c = ms_CompareString(m$,m2$)
if c=1
changed = 1
inc actpos
for Pos2 = ms_List_ActPos to Pos+1 step -1
ms_Temp_item$(Pos2)=ms_Temp_item$(Pos2-1)
next Pos2
ms_Temp_Item$(Pos) = m$
exit
endif
next Pos
if changed = 0
inc Actpos
ms_Temp_item$(Actpos) = m$
endif
next X
for X = 1 to ms_List_ActPos
ms_ListItem$(X) = ms_Temp_Item$(X)
next X
undim ms_Temp_Item$(0)
endfunction
REM *************************************************************************
REM *************************************************************************
function ms_MirrorList()
dim ms_Temp_Item$(ms_List_ActPos)
for X = 1 to ms_List_ActPos
ms_Temp_item$(X)=ms_ListItem$(X)
next X
for X = 1 to ms_List_ActPos
ms_ListItem$(X) = ms_Temp_item$(ms_List_ActPos-X+1)
next X
endfunction
REM *************************************************************************
REM *************************************************************************
function ms_ListString$(Position)
String$ = ms_ListItem$(Position)
endfunction String$
REM *************************************************************************
REM *************************************************************************
function ms_TotalListItems()
endfunction ms_List_ActPos
REM *************************************************************************
REM *************************************************************************
function ms_MaxListItems()
endfunction ms_List_MaxElements
REM *************************************************************************
REM *************************************************************************
function ms_PrintList()
for X = 1 to ms_List_ActPos
print "List Element "+str$(X)+": "+ms_ListItem$(X)
next X
endfunction
REM *************************************************************************
So... any comments, constructive criticism etc. are appreciated.
I hope, that the functions are helpful to anyone out there, and that they will be used by someone.
Thanks.
Visit the DBPro - Speed up your game-Thread. http://forum.thegamecreators.com/?m=forum_view&t=88661&b=1