Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to convert accented characters to unaccented ones Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
20-Oct-02
Category
Object Pascal-Strings
Language
Delphi 2.x
Views
81
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius

Is there a way to convert accented characters to unaccented (meaning ASCII A - Z, a 
- z)?

Answer:

The classical way is to have a conversion table and do a lookup in that table. The 
problem with that is that the table is of course specific to a certain charset 
(encoding), like Windows Latin-1. You could build a table for a range of UNICODE 
(widechar) characters to get around this limitation and convert the strings to 
widestrings before you do the accent removals. The routine below uses ANSI 
characters with the Windows western (Latin-1) encoding.

1   function SimplifyChar(const _ch: char): char;
2   const
3     Charmap: array[#128..#255] of Char = (
4       #128 { ? }, #129 { ? }, #130 { ? }, #131 { ? }, #132 { ? },
5       #133 { ? }, #134 { ? }, #135 { ? }, #136 { ? }, #137 { ? },
6       #138 { ? }, #139 { ? }, #140 { ? }, #141 { ? }, #142 { ? },
7       #143 { ? }, #144 { ? }, #145 { ? }, #146 { ? }, #147 { ? },
8       #148 { ? }, #149 { ? }, #150 { ? }, #151 { ? }, #152 { ? },
9       #153 { ? }, #154 { ? }, #155 { ? }, #156 { ? }, #157 { ? },
10      #158 { ? }, #159 { ? }, #160 {  }, #161 {  }, #162 {  },
11      #163 {  }, #164 {  }, #165 {  }, #166 {  }, #167 {  },
12      #168 {  }, #169 {  }, #170 {  }, #171 {  }, #172 {  },
13      #173 {  }, #174 {  }, #175 {  }, #176 {  }, #177 {  },
14      #178 {  }, #179 {  }, #180 {  }, #181 {  }, #182 {  },
15      #183 {  }, #184 {  }, #185 {  }, #186 {  }, #187 {  },
16      #188 {  }, #189 {  }, #190 {  }, #191 {  }, 'A' {  },
17      'A' {  }, 'A' {  }, 'A' {  }, 'A' {  }, 'A' {  },
18      #198 {  }, #199 {  }, 'E' {  }, 'E' {  }, 'E' {  },
19      'E' {  }, 'I' {  }, 'I' {  }, 'I' {  }, 'I' {  },
20      #208 {  }, #209 {  }, 'O' {  }, 'O' {  }, 'O' {  },
21      'O' {  }, 'O' {  }, #215 {  }, #216 {  }, 'U' {  },
22      'U' {  }, 'U' {  }, 'U' {  }, #221 {  }, #222 {  },
23      #223 {  }, 'a' {  }, 'a' {  }, 'a' {  }, 'a' {  },
24      'a' {  }, 'a' {  }, #230 {  }, #231 {  }, 'e' {  },
25      'e' {  }, 'e' {  }, 'e' {  }, 'i' {  }, 'i' {  },
26      'i' {  }, 'i' {  }, #240 {  }, #241 {  }, 'o' {  },
27      'o' {  }, 'o' {  }, 'o' {  }, 'o' {  }, #247 {  },
28      #248 {  }, 'u' {  }, 'u' {  }, 'u' {  }, 'u' {  },
29      #253 {  }, #254 {  }, #255 {  }
30      );
31  begin
32    if _ch >= #128 then
33      Result := Charmap[_ch]
34    else
35      Result := _ch;
36  end;
37  
38  //The charmap table was created by this little routine and then edited:
39  
40  procedure CreateCharacterMap(fromchar, tochar: Char);
41  
42  function DisplayStr(const ch: Char): string;
43  begin
44    if ch < #32 then
45      Result := '^' + Chr(Ord('A') - 1 + Ord(ch))
46    else
47      Result := ch;
48  end;
49  
50  var
51    sl: TStringlist;
52    line, element: string;
53    ch: char;
54  begin
55    Assert(fromchar <= tochar);
56    sl := Tstringlist.Create;
57    try
58      sl.Add('Const');
59      line := Format('  Charmap: array [#%d..#%d] of Char = (', [Ord(fromchar),
60        Ord(tochar)]);
61      sl.Add(line);
62      line := '';
63      for ch := fromchar to toChar do
64      begin
65        element := Format('#%3.3d { %s }', [Ord(ch), DisplayStr(ch)]);
66        if (Length(line) + Length(element)) > 66 then
67        begin
68          sl.Add('    ' + line);
69          line := '';
70        end;
71        line := line + element;
72        if ch <> tochar then
73          line := line + ', ';
74      end;
75      sl.Add('    ' + line);
76      sl.add('    );');
77      Clipboard.AsText := sl.Text;
78    finally
79      sl.Free
80    end;
81  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC