Getting a unicode, hidden symbol, as data in Delphi

1.4k Views Asked by At

I'm writing a delimiter for some Excel spreadsheet data and I need to read the rightward arrow symbol and pilcrow symbol in a large string.

The pilcrow symbol, for row ends, was fairly simply, using the Chr function and the AnsiChar code 182.

The rightward arrow has been more tricky to figure out. There isn't an AnsiChar code for it. The Unicode value for it is '2192'. I can't, however, figure out how to make this into a string or char type for me to use in my function.

Any easy ways to do this?

2

There are 2 best solutions below

7
On

You need to represent that character as a UTF-16 character. In Unicode Delphi you would do it like this:

Chr(2192)

which is of type WideChar.

However, you are using Delphi 7 which is a pre-Unicode Delphi. So you have to do it like this:

var
  wc: WideChar;
....
wc := WideChar(2192);

Now, this might all be to no avail for you since it sounds a little like your code is working with 8 bit ANSI text. In which case that character cannot be encoded in any 8 bit ANSI character set. If you really must use that character, you'll need to use Unicode text.

1
On

You can't use the 2192 character directly. But since a STRING variable can't contain this value either (as thus your TStringList can't either), that doesn't matter.

What character(s) are the 2192 character represented as in your StringList AFTER you have read it in? Probably by these three separate characters: 0xE2 0x86 0x92 (in UTF-8 format). The simple solution, therefore, is to start by replacing these three characters with a single, unique character that you can then assign to the Delimiter field of the TStringList.

Like this:

.
.
.
<Read file into a STRING variable, say S>
S := ReplaceStr(S,#$E2#$86#$92,'|');
SL := TStringList.Create;
SL.Text := S;
SL.Delimiter := '|';
.
.
.

You'll have to select a single-character representation of your 3-byte UTF-8 Unicode character that doesn't occur in your data elsewhere.