"Negative" byte values and chars...

Share your advanced PureBasic knowledge/code with the community.
User avatar
Michael Vogel
Addict
Addict
Posts: 2811
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

"Negative" byte values and chars...

Post by Michael Vogel »

Code updated for 5.20+. PureBasic now support 'PeekA()' for unsigned.

Be careful, when manipulating strings with the PeekB command!

When the result is a char represented by a value between 0 and 127 everything will be fine, but there could be a problem when dealing with other chars like I tried with the following line...

Code: Select all

If PeekB(@s+Dummy)='Ã'
this will never get #True until you change the line to...

Code: Select all

If PeekB(@s+Dummy)&$ff='Ã'
So be careful
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

You could switch PeekB() for PeekC() instead.
I may look like a mule, but I'm not a complete ass.
User avatar
Michael Vogel
Addict
Addict
Posts: 2811
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Post by Michael Vogel »

srod wrote:You could switch PeekB() for PeekC() instead.
Thanks, works fine!

Code: Select all

s.s="got it....Ã... or not?"

dummy=Len(s)
While Dummy
   dummy-1
  If PeekC(@s+Dummy)='Ã'
    Debug "Bingo"
  EndIf
Wend
ABBKlaus
Addict
Addict
Posts: 1143
Joined: Sat Apr 10, 2004 1:20 pm
Location: Germany

Post by ABBKlaus »

and unicode :wink:

Code: Select all

s.s="got it....Ã... or not?" 
Debug s
dummy=Len(s)
While Dummy 
  dummy-1
  ;Debug PeekC(@s+Dummy*SizeOf(character))
  If PeekC(@s+Dummy*SizeOf(character))='Ã'
    Debug "Bingo" 
  EndIf 
Wend
Debug ""
Debug 'Ã'
Debug ""
Debug Asc("Ã")
but works only when sourcefile encoding is plain text !
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Looks like .c and .character variables are only intended to store character types. And it is dangerous to use it to store numbers for use for other goals. :?
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Post Reply