[fpc-pascal] Reading and writing char

Tomas Hajny XHajT03 at hajny.biz
Thu Oct 6 10:59:53 CEST 2011


On Thu, October 6, 2011 10:21, Thomas Young wrote:
>
> Thank you for the article. It was very helpful.
>
> Why is it I can read and write a string that contains characters in the
> upper 128 but can't read & write them as individual char?

This is most probably due to the fact that your platform uses/requires a
multi-byte encoding of these characters nowadays (probably UTF-8) as
opposed to the platform / version you used those 'years ago' with
ThinkPascal. You need a different way for referring to the particular
characters than you used in the past, or you need to translate the
original meaning (based on a particular character set like Mac Roman you
may have used in the past).


> Specifically I need to read the copyright (169), trademark (170) and
> registration (168) characters. Any suggestions on how I can do this?

If you specifically need these, put those characters as constant strings
in your code and use those strings. Also, make sure to specify the
encoding used for your source code directly in the source code (using the
respective compiler directive or the UTF-8 marker) to avoid possible wrong
interpretation.

Tomas



>
> On Oct 6, 2011, at 2:23 AM, David Emerson wrote:
>
>> On Wed 5 Oct 2011, Thomas Young wrote:
>>> Hi,
>>>
>>> I'm trying to read and write ascii characters using FPC. I had no
>>> problems
>>> doing this years ago with Think Pascal & Code Warrior.
>>>
>>> For some reason I'm not able to read and write ascii characters above
>>> ascii
>>> 127 with FPC. Can someone explain this to me?
>>>
>>> Thanks in advance!
>>
>> The world has changed, and globalization has reached your computer. Your
>> computer is almost definitely using a different character set today than
>> it was
>> back in those days long ago. read this:
>> http://www.joelonsoftware.com/articles/Unicode.html
>> The Absolute Minimum Every Software Developer Absolutely, Positively
>> Must Know
>> About Unicode and Character Sets (No Excuses!)
>>
>> ~D.
>>
>>>
>>> Using this code:
>>> 	for i:= 33 to 226 do
>>> 		writeln('Character: ', chr(i), '   Ascii value: ', i:1);
>>>
>>> Character: !   Ascii value: 33
>>> Character: "   Ascii value: 34
>>> Character: #   Ascii value: 35
>>> Character: $   Ascii value: 36
 .
 .
>>> Character: ~   Ascii value: 126
>>> Character:    Ascii value: 127
>>> Character: ?   Ascii value: 128
>>> Character: ?   Ascii value: 129
>>> Character: ?   Ascii value: 130
>>> Character: ?   Ascii value: 131
>>> Character: ?   Ascii value: 132
>>> Character: ?   Ascii value: 133





More information about the fpc-pascal mailing list