Page 1 of 1

about PeekS

Posted: Tue Nov 29, 2016 9:12 am
by applePi
how to let Trond code here to work in PB 5.50 :
http://purebasic.fr/english/viewtopic.php?f=13&t=25999
Thanks

Re: about PeekS

Posted: Tue Nov 29, 2016 9:27 am
by falsam
[PB 5.50]

Code: Select all

a$ = "the cat in the hat "
Length = Len(a$)
For t=1 To Length
  Letter.s = PeekS(Ascii(a$)+t-1, 1, #PB_UTF8)
  Word.s = Word + Letter
  If Letter = " "
    Debug Word + "."
   ; or some other process
    Word = ""
  EndIf
Next
Result
the .
cat .
in .
the .
hat .

Re: about PeekS

Posted: Tue Nov 29, 2016 9:31 am
by Fred
Here is the version which should work in ascii and unicode mode:

Code: Select all

a$ = "the cat in the hat "
Length = Len(a$)
For t=1 To Length
  Letter.s = PeekS(@a$+(t-1)*SizeOf(Character), 1)
  Word.s = Word + Letter
  If Letter = " "
    Debug Word + "."
   ; or some other process
    Word = ""
  EndIf
Next
Also Ascii() return a dynamic buffer which needs to be freed or you will experience a leak.

Re: about PeekS

Posted: Tue Nov 29, 2016 9:36 am
by Demivec

Code: Select all

a$ = "the cat in the hat "
Length = Len(a$)
For t=1 To Length
  Letter.s = PeekS(a$+(t-1) * SizeOf(Character), 1)
  Word.s = Word + Letter
  If Letter = " "
    Debug Word + "."
   ; or some other process
    Word = ""
  EndIf
Next 
@Edit: Fred beat me to it.

Re: about PeekS

Posted: Tue Nov 29, 2016 12:04 pm
by netmaestro
If one is being asked to take a string consisting of an expression in human language and break it down into its individual words, the first option from PureBasic that comes to mind is StringField(). Is there a reason to dismiss it and look elsewhere?

Re: about PeekS

Posted: Tue Nov 29, 2016 1:08 pm
by applePi
Thanks for the solutions
StringField(). Is there a reason to dismiss it and look elsewhere?
no i know StringField() is a good and better choice https://www.purebasic.com/documentation ... field.html
it is may be not available in 2007 purebasic version
i just want the PeekS to work.

Re: about PeekS

Posted: Tue Nov 29, 2016 1:40 pm
by ts-soft
applePi wrote:it is may be not available in 2007 purebasic version
StringField()?

StringField is available since 9. Oktober 2002, PB Version 3.40.