Solved

Windows to Mac Text Translator

Posted on 2010-09-14
6
462 Views
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
characters.zip
0
Comment
Question by:ioannisa
  • 3
  • 3
6 Comments
 
LVL 22

Expert Comment

by:8080_Diver
ID: 33675239
Check the following for some guidance:
http://weblogs.asp.net/ahoffman/archive/2004/01/19/60094.aspx
0
 
LVL 6

Author Comment

by:ioannisa
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;
end;

//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;
begin
    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:='½';
end;

Open in new window

0
 
LVL 22

Accepted Solution

by:
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.
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 6

Author Comment

by:ioannisa
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
translator.zip
0
 
LVL 6

Author Comment

by:ioannisa
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 :)
0
 
LVL 22

Expert Comment

by:8080_Diver
ID: 33686768
joannisa,
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! ;_)
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
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.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
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 …

707 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now