Code archives/Algorithms/String parsing functions

This code has been declared by its author to be Public Domain code.

Download source code

String parsing functions by bytecode772006
These are a few functions which are used in my gui for parsing strings.

;Parse$()
Parse$(message$, item, seperator$)

string$ = "blah,lol,beep"
x$ = Parse$(string$, 2, ",")
;x$ will be "lol"

LoadFont("Arial,20,1,0,0")
GetParam(file_path$, param$)
;======
;file content:
blah = 1
lol = 2
beep = 3

win_mode = GetParam("Gfx.ini", "Windowmode")
Graphics 1024, 768, 32, win_mode
Function Parse$(msg$, item, sep$ = ",")
Repeat
	fas = Instr(msg$, sep$, fas + 1)
	count = count + 1
Until fas = 0 Or count = item
If fas = 0 And item > 0 Then Return
spos = fas + 1
epos = Instr(msg$ + sep$, sep$, fas + 1)
Return Mid(msg$, spos, epos - spos)
End Function

Function GetParam$(path$, p$)
file = ReadFile(path$)
While Not Eof(file)
	l$ = Replace(ReadLine(file), " ", "")
	If GUI_Parse(l$, 0, "=") = p$ Then
		txt$ = GUI_Parse(l$, 1, "=")
		txt$ = Replace(txt$, Chr(34), "")
		txt$ = Replace(txt$, "~", " ")
		Exit
	EndIf
Wend
CloseFile file
If txt$ = "" Then RuntimeError "GUI_GetParam$() failed."
Return txt$
End Function

Function LoadFont(fnt$)
Return LoadFont(GUI_Parse(fnt$, 0), GUI_Parse(fnt$, 1), GUI_Parse(fnt$, 2), GUI_Parse(fnt$, 3), GUI_Parse(fnt$, 4))
End Function

Comments

None.

Code Archives Forum