Advertisement
jargon

jargon's String/uByte Conversion for FreeBASIC

Mar 14th, 2024 (edited)
1,394
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. '"ascii ubyte.bas"
  3. 'String/uByte Conversion for FreeBASIC
  4. 'Copyright 2024 03/14 Tim Keal alias jargon
  5.  
  6. Const NULL As Any Ptr = 0
  7.  
  8. #Define EQU =
  9. #Define GTR >
  10. #Define LSS <
  11. #Define NEQ <>
  12. #Define GEQ >=
  13. #Define LEQ <=
  14.  
  15. Const EMPTY = ""
  16.  
  17. declare sub ascii2array(byval text as string=EMPTY, array(any) as ubyte )
  18.  
  19. declare sub array2ascii(byref text as string=EMPTY, array(any) as ubyte )
  20.  
  21. sub ascii2array(byval text as string=EMPTY, array(any) as ubyte )
  22.    
  23.     erase array
  24.    
  25.     dim as longint offset=0,index=0
  26.    
  27.     do
  28.         if offset GEQ len(text) then exit do
  29.        
  30.         redim preserve array(LBound(array,1) to UBound(array,1))
  31.        
  32.         array(offset)=asc(mid(text,offset+1,1))
  33.    
  34.         offset+=1
  35.        
  36.     loop
  37.    
  38. end sub
  39.  
  40. sub array2ascii(byref text as string=EMPTY, array(any) as ubyte )
  41.    
  42.     text = EMPTY
  43.    
  44.     dim as longint offset=0,index=0
  45.    
  46.     offset = LBound(array,1)
  47.    
  48.     do
  49.         if offset GTR UBound(array,1) then exit do
  50.        
  51.         text &= chr(array(offset))
  52.        
  53.         offset+=1
  54.        
  55.     loop
  56.    
  57. end sub
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement