Windows to Mac Text Translator

Posted on 2010-09-14
Last Modified: 2013-11-23
Dear all,

I am working with Delphi2009.

I want to create a translator that translates text files between simple ANSI encoding and the MAC equivalent.  Problem seems to exist with greek characters.

Thought of doing a character map with the changed characters and check for each character in my text indivicually if that character exists in my character map array to replace it, but it takes much time.

I attach a file with the two equivalents.  Need to find out how to utilize character mapping so I produce one from the other and vise versa.

Any help would be appreciated
Question by:ioannisa
  • 3
  • 3
LVL 22

Expert Comment

ID: 33675239
Check the following for some guidance: 

Author Comment

ID: 33680888
Sorry it doesn't help.

I have the conversion using an array of a record

// this is the delphi RECORD
type converter=RECORD
    mac,win: char;

//this is the array of "converter" RECORDS
conv_table: array[1..67] of converter;

// this is the method that holds the mapping
procedure TForm1.initConverter;
    conv_table[01].win:='a'; conv_table[01].mac:='a';
    conv_table[02].win:='ß'; conv_table[02].mac:='ß';
    conv_table[03].win:='¿'; conv_table[03].mac:='¿';
    conv_table[04].win:='d'; conv_table[04].mac:='d';
    conv_table[05].win:='e'; conv_table[05].mac:='e';
    conv_table[06].win:='¿'; conv_table[06].mac:='¿';
    conv_table[07].win:='¿'; conv_table[07].mac:='¿';
    conv_table[08].win:='¿'; conv_table[08].mac:='¿';
    conv_table[09].win:='¿'; conv_table[09].mac:='¿';
    conv_table[10].win:='¿'; conv_table[10].mac:='¿';
    conv_table[11].win:='¿'; conv_table[11].mac:='µ';
    conv_table[12].win:='µ'; conv_table[12].mac:='¿';
    conv_table[13].win:='¿'; conv_table[13].mac:='¿';
    conv_table[14].win:='¿'; conv_table[14].mac:='¿';
    conv_table[15].win:='¿'; conv_table[15].mac:='¿';
    conv_table[16].win:='p'; conv_table[16].mac:='p';
    conv_table[17].win:='¿'; conv_table[17].mac:='¿';
    conv_table[18].win:='s'; conv_table[18].mac:='s';
    conv_table[19].win:='t'; conv_table[19].mac:='t';
    conv_table[20].win:='¿'; conv_table[20].mac:='¿';
    conv_table[21].win:='f'; conv_table[21].mac:='¿';
    conv_table[22].win:='¿'; conv_table[22].mac:='¿';
    conv_table[23].win:='¿'; conv_table[23].mac:='¿';
    conv_table[24].win:='¿'; conv_table[24].mac:='f';

    conv_table[25].win:='¿'; conv_table[25].mac:='°';
    conv_table[26].win:='¿'; conv_table[26].mac:='µ';
    conv_table[27].win:='G'; conv_table[27].mac:='¿';
    conv_table[28].win:='¿'; conv_table[28].mac:='¿';
    conv_table[29].win:='¿'; conv_table[29].mac:='¶';
    conv_table[30].win:='¿'; conv_table[30].mac:='·';
    conv_table[31].win:='¿'; conv_table[31].mac:='¿';
    conv_table[32].win:='T'; conv_table[32].mac:='£';
    conv_table[33].win:='¿'; conv_table[33].mac:='¿';
    conv_table[34].win:='¿'; conv_table[34].mac:='¿';
    conv_table[35].win:='¿'; conv_table[35].mac:='¤';
    conv_table[36].win:='¿'; conv_table[36].mac:='»';
    conv_table[37].win:='¿'; conv_table[37].mac:='¿';
    conv_table[38].win:='¿'; conv_table[38].mac:='¥';
    conv_table[39].win:='¿'; conv_table[39].mac:='G';
    conv_table[40].win:='¿'; conv_table[40].mac:='¦';
    conv_table[41].win:='¿'; conv_table[41].mac:='¿';
    conv_table[42].win:='S'; conv_table[42].mac:='¿';
    conv_table[43].win:='¿'; conv_table[43].mac:='¿';
    conv_table[44].win:='¿'; conv_table[44].mac:='¿';
    conv_table[45].win:='F'; conv_table[45].mac:='¿';
    conv_table[46].win:='¿'; conv_table[46].mac:='¿';
    conv_table[47].win:='¿'; conv_table[47].mac:='¿';
    conv_table[48].win:='O'; conv_table[48].mac:='¿';

    conv_table[49].win:='¿'; conv_table[49].mac:='¿';

    conv_table[50].win:='¿'; conv_table[50].mac:='¿';
    conv_table[51].win:='¿'; conv_table[51].mac:='¿';
    conv_table[52].win:='¿'; conv_table[52].mac:='¿';
    conv_table[53].win:='¿'; conv_table[53].mac:='¿';
    conv_table[54].win:='¿'; conv_table[54].mac:='¿';
    conv_table[55].win:='¿'; conv_table[55].mac:='¿';
    conv_table[56].win:='¿'; conv_table[56].mac:='¿';

    conv_table[57].win:='¿'; conv_table[57].mac:='¿';
    conv_table[58].win:='¿'; conv_table[58].mac:='¿';
    conv_table[59].win:='¿'; conv_table[59].mac:='¿';
    conv_table[60].win:='¿'; conv_table[60].mac:='¿';
    conv_table[61].win:='¿'; conv_table[61].mac:='¿';
    conv_table[62].win:='¿'; conv_table[62].mac:='¿';

    conv_table[62].win:='¿'; conv_table[62].mac:='¿';
    conv_table[63].win:='¿'; conv_table[63].mac:='¿';
    conv_table[64].win:='¿'; conv_table[64].mac:='¿';
    conv_table[65].win:='¿'; conv_table[65].mac:='¿';

    conv_table[66].win:='¿'; conv_table[66].mac:='«';
    conv_table[67].win:='¿'; conv_table[67].mac:='½';

Open in new window

LVL 22

Accepted Solution

8080_Diver earned 500 total points
ID: 33684249
Okay, let's back up a bit.
Problem seems to exist with greek characters.
Can you describe what the problem is?  I was assuming that you were getting display errors but that may not be the case.
If you want the fastest way to translate from one character to another, put the two sets of characters in sepearate strings in correstponding order.  Then you can use the POS function to find the position in the first string and then select the character from that position in the second string in order to translate.  It also gives you the ability to go either direction.
Try this link for more on the subject . . . it seems to be very thorough.
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!


Author Comment

ID: 33684330
Ok, I followed a technique close to that.

I made use of hashtables for the translation.  More specifically I made few changes to a hashtable class provided by Niclas Svan, by adding an extra constructor where you can specify if you want CaseSensitive keys and values so that you can distinguish between upper and lower case letters when you search, and I also provided a backwards check by adding "function GetKey(const strVal : string): string;".

These to the actual unit being used.  On top of that I added another unit of mine that does the transform by allowing the user to either create an object and work though it, or by making static calls.

Check it out before I deliver you the points

Author Comment

ID: 33684363
To also explain you what I wanted, from the initial post of mine I had two files.

The windows file created and saved.  And then the Macintosh equivalent so it can be read by macintosh machines.  Therefore I wanted to get a fast algorithm to translate characters found in WIN-TEXT to the equivalent MAC-TEXT.

For the set of the characters concerned that seemed to be wrong, I provided my own solution on my above text.

However I will award you the points, because the techique followed is somewhat close to the way you instructed me on your second reply :)
LVL 22

Expert Comment

ID: 33686768
Thank you for your generosity and I am glad I was of (at least some ;-) assistance.
I have played in the same arena in the past (albeit not involving Mac's ;-).  I know how frustrating things can get when you are translating characters.
Good luck and have fun! ;_)

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question