#1 2022-11-08 06:30

terrytw
Member
Registered: 2022-11-08
Posts: 2

Converting Unicode to text

Hello everyone, I have run into a problem, and I don't know how to code, so even though I have been banging my head at it for several hours, I have still not figured it out.

Here is the file name example:

@4f60@597d@5927@5bb6.pdf

I have figured it out that these are Unicode format letters. But I have not found out how to transit these back to the original text that they stands for. I recon it involves using pascal script, but like I said, I can't figure it out.

Can someone please help? Thank you!


And to Denis, thank you for this clean and powerful software! I like it a lot!

Last edited by terrytw (2022-11-08 07:32)

Offline

#2 2022-11-09 16:10

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,440

Re: Converting Unicode to text

The script included below will convert those Unicode hex codes into the underlying characters.

The example filename "@4f60@597d@5927@5bb6.pdf" will get converted to "你好大家.pdf".

var
  Positions: TIntegerArray;
  Matches: TWideStringArray;
  I, CountMatches: Integer;
  Character: WideString;
  CharacterCode: Word;
begin
  CountMatches := FindRegEx(FileName, '@[0-9a-f]{4}\b', False, Positions, Matches);
  for I := CountMatches - 1 downto 0 do
  begin
    Character := WideCopy(FileName, Positions[I] + 1, Length(Matches[I]) - 1);
    CharacterCode := HexToInt(Character);
    Character := WideChr(CharacterCode);
    WideDelete(FileName, Positions[I], Length(Matches[I]));
    WideInsert(Character, FileName, Positions[I]);
  end;
end.

This script is for the Pascal Script rule.

Offline

#3 2022-11-14 02:26

terrytw
Member
Registered: 2022-11-08
Posts: 2

Re: Converting Unicode to text

Wow, many thanks to you!

I did not expect it to be such a hassle, I though it would be s simple 2 liner using a function.

Sorry for the trouble...

Offline

Board footer

Powered by FluxBB