0

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?

Chucky
  • 1,701
  • 7
  • 28
  • 62

2 Answers2

2

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.

HeartWare
  • 7,464
  • 2
  • 26
  • 30
1

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.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • Okay then. I am using Delphi 7 so I did try WideChar(2192). But my function does require a Char, not a WideChar. Is there anyway to get this rightward arrow as a char? – Chucky Jan 09 '14 at 15:27
  • 1
    You've got a square peg and a round hole. That character does not exist in 8 bit ANSI encodings. Think about it. There are only 256 characters available in 8 bit ANSI. – David Heffernan Jan 09 '14 at 15:30
  • I get you. The problem I'm facing is the delimiter field of TStringList only accepts chars. I don't know how to get around this as the data I'm dealing with is by default rightward arrows. To be continued. – Chucky Jan 09 '14 at 15:33
  • 1
    Why are you operating on Unicode data with D7 TStringList? You need to operate on Unicode data. – David Heffernan Jan 09 '14 at 16:11
  • 1
    @Chucky use TWideStringList from Jedi CodeLib then – Arioch 'The Jan 09 '14 at 17:56
  • I ended up swapping the weird symbols for easier-to-manipulate AnsiChars. It appears to have done the trick so I'm satisfied. Thanks for the insight, everyone. – Chucky Jan 10 '14 at 14:41
  • You should consider accepting the answer that you feel is the best answer to the question you asked. – David Heffernan Jan 10 '14 at 16:25