about PeekS

Just starting out? Need help? Post your questions and find answers here.
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

about PeekS

Post 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
User avatar
falsam
Enthusiast
Enthusiast
Posts: 632
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

Re: about PeekS

Post 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 .

➽ Windows 11 64-bit - PB 6.21 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti

Sorry for my bad english and the Dunning–Kruger effect 🤪
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: about PeekS

Post 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.
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: about PeekS

Post 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.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: about PeekS

Post 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?
BERESHEIT
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: about PeekS

Post 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.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: about PeekS

Post 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.
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Post Reply