Author Topic: Creating a Set of strings  (Read 3015 times)

0 Members and 1 Guest are viewing this topic.

Charles Pegge

  • Guest
Creating a Set of strings
« on: June 02, 2012, 04:11:21 AM »
All the strings are contained in one string

Code: OxygenBasic
  1.  
  2.  
  3. s="one,two,three,four,five,six,"
  4.  
  5. 'mark string into null strings
  6. '=============================
  7.  
  8. 'replace commas with nulls
  9. 'creates series of zstrings
  10.  
  11. c=0
  12. i=1
  13. le=len s
  14. byte *b : @b=strptr s
  15. do
  16.   if i>le then exit do
  17.   if b=44 then
  18.     b=0 'patch null
  19.    c++
  20.   end if
  21.   i++
  22.   @b++
  23. end do
  24.  
  25.  
  26. 'create array of zstring pointers
  27. '================================
  28.  
  29. sys pz[100]
  30. ps=strptr(s)-1
  31. nl=chr(0)
  32. j=1
  33. i=0
  34. do
  35.   i++
  36.   if i>c then exit do
  37.   pz[ i ]=ps+j
  38.   j=1+instr j,s,nl
  39. end do
  40. c=i-1
  41.  
  42.  
  43. 'display
  44. '=======
  45.  
  46. cr=chr(13)+chr(10)
  47. tab=chr(9)
  48. pr="sub strings" cr cr
  49. for i=1 to c
  50.   pr+=i tab cast char * pz[ i ] cr
  51. next
  52.  
  53. print pr
  54.  

Charles

Aurel

  • Guest
Re: Creating a Set of strings
« Reply #1 on: June 02, 2012, 06:09:43 AM »
Charles...
When i try this code i recive linker error about : cast
What's that mean ?

is there a way to write this line little bit more basic-like?

Code: [Select]
pr+=i tab cast char * pz[ i ] cr

Charles Pegge

  • Guest
Re: Creating a Set of strings
« Reply #2 on: June 02, 2012, 08:47:42 AM »
Hi Aurel, I introduced this quite recently.

cast is used to make a variable appear as a different type, like casting an actor to play Hamlet.

This is a sys variable, but we want it to be used as a char* or zstring * if you prefer.

You can try as instead:

pr+=i tab  as char * pz[ i ] cr

Charles

Aurel

  • Guest
Re: Creating a Set of strings
« Reply #3 on: June 02, 2012, 10:04:01 AM »
Hi Charles..
I think that i understand what casting mean because i use this way in EB programming to.
But with different ( read C-like syntax ) like :
pMem = NEW(CHAR,100)
*<CHAR>(pMem+x) = x+1

Is this same or similiar?
Infact i want to ask ,is cast in latest oxygen.dll or in gxo.exe ?

yes..i try
 pr = pr str(i) tab  As char *pz[ i ]   cr

and work fine ;)
« Last Edit: June 02, 2012, 10:15:16 AM by Aurel »