Page 1 of 1

"Negative" byte values and chars...

Posted: Fri Jun 02, 2006 12:21 pm
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

Posted: Fri Jun 02, 2006 1:11 pm
by srod
You could switch PeekB() for PeekC() instead.

Posted: Fri Jun 02, 2006 1:20 pm
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

Posted: Fri Jun 02, 2006 11:07 pm
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 !

Posted: Sat Jun 03, 2006 9:24 am
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. :?