December 03, 2020, 07:25:12 PM

Author Topic: [bb] String parsing functions by bytecode77 [ 1+ years ago ]  (Read 438 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
Title : String parsing functions
Author : bytecode77
Posted : 1+ years ago

Description : These are a few functions which are used in my gui for parsing strings.

Code: [Select]
;Parse$()
Parse$(message$, item, seperator$)

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

Code: [Select]
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


Code :
Code: BlitzBasic
  1. Function Parse$(msg$, item, sep$ = ",")
  2. Repeat
  3.         fas = Instr(msg$, sep$, fas + 1)
  4.         count = count + 1
  5. Until fas = 0 Or count = item
  6. If fas = 0 And item > 0 Then Return
  7. spos = fas + 1
  8. epos = Instr(msg$ + sep$, sep$, fas + 1)
  9. Return Mid(msg$, spos, epos - spos)
  10. End Function
  11.  
  12. Function GetParam$(path$, p$)
  13. file = ReadFile(path$)
  14. While Not Eof(file)
  15.         l$ = Replace(ReadLine(file), " ", "")
  16.         If GUI_Parse(l$, 0, "=") = p$ Then
  17.                 txt$ = GUI_Parse(l$, 1, "=")
  18.                 txt$ = Replace(txt$, Chr(34), "")
  19.                 txt$ = Replace(txt$, "~", " ")
  20.                 Exit
  21.         EndIf
  22. Wend
  23. CloseFile file
  24. If txt$ = "" Then RuntimeError "GUI_GetParam$() failed."
  25. Return txt$
  26. End Function
  27.  
  28. Function LoadFont(fnt$)
  29. Return LoadFont(GUI_Parse(fnt$, 0), GUI_Parse(fnt$, 1), GUI_Parse(fnt$, 2), GUI_Parse(fnt$, 3), GUI_Parse(fnt$, 4))
  30. End Function


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal