Модераторы: Poseidon, Snowy, bems, MetalFan
  

Поиск:

Ответ в темуСоздание новой темы Создание опроса
> Как конвертировать Ansi->USC2 и обратно, Может кто поможет 
:(
    Опции темы
Vovam_mail
  Дата 5.6.2005, 15:06 (ссылка)    |    (голосов: 0) Загрузка ... Загрузка ... Быстрая цитата Цитата


Unregistered











0430 0431 0432 0433 0434 0435 0451 0436 0437 0438 0439 043A 043B 043C 043D
а б в г д е ё ж з и й к л м н

Это выглядит так, smile Мастера помогите-это решить програмно туда и обратно
не писать же так,
это только пример прошу не обращать особого внимания на код в нутри

Код

function AnsiToUcs(Convert:string):string;
var
f:string;
i:integer;
begin
result:='';
for i:=1 to Length(Convert) do begin
f:=Convert[i];
if f='а' then result:=result+'0410;
if f='б' then result:=result+'0411';
if f='в' then result:=result+'0412';
end;
end;


а то мне не доходит.

Это сообщение отредактировал(а) Girder - 6.6.2005, 13:31
  Вверх
Dynamic
Дата 5.6.2005, 16:25 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Опытный
**


Профиль
Группа: Участник
Сообщений: 372
Регистрация: 5.7.2004
Где: Салехард

Репутация: 12
Всего: 15



Так, что ли?
Код
type
    USC = $0430..$043D;
const
      ASC = ['а'..'н'];

function AnsiToUcs(const Convert:string; Delim: Char):string;
var i: integer;
begin
     Result := '';
     for i := 1 to Length(Convert) do
      if Convert[i] in ASC then
       Result := Result + IntToHex(Low(USC) + Ord(Convert[i])-Ord('à')) + Delim;
end;

function UcsToAnsi(const Convert:string; Delim: Char):string;
var L: TStrings;
    i, c: integer;
begin
     Result := '';
     L := TStringList.Create;
     try
       L.Delimiter := Delim;
       L.DelimitedText := Convert;
       for i := 0 to L.Count-1 do
       begin
         c := StrToIntDef('$'+L[i], -1);
         if (c <> -1) and (c <= High(USC)) then
          Result := Result + Chr(Ord('а') + c - Low(USC));
       end;
     finally
       L.Free;
     end;
end;

procedure TForm1.Button2Click(Sender: TObject);
var s: string;
begin
     s := 'а б в г д е ё ж з и й к л м н';
     s := AnsiToUcs(s, ' ');
     ShowMessage(s);
     s := UcsToAnsi(s, ' ');
     ShowMessage(s);
end;


Это сообщение отредактировал(а) Dynamic - 5.6.2005, 16:48


--------------------
Было бы о чем молчать, а уж что сказать – всегда найдется...
PM MAIL WWW   Вверх
Vovanmail
Дата 5.6.2005, 17:02 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Новичок



Профиль
Группа: Участник
Сообщений: 7
Регистрация: 5.6.2005

Репутация: нет
Всего: нет



Dynamic smile Спасибо. Сейчас попробую

Result := Result + IntToHex(Low(USC) + Ord(Convert[i])-Ord('à')) + Delim;
ругается на это

Это сообщение отредактировал(а) Vovanmail - 5.6.2005, 17:29
PM MAIL   Вверх
Vovanmail
Дата 6.6.2005, 09:07 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Новичок



Профиль
Группа: Участник
Сообщений: 7
Регистрация: 5.6.2005

Репутация: нет
Всего: нет



smile А мне бы, для всего ряда бы, конвертор бы. Тобишь всей кодовой страницы Английского руского языков. Пытаюсь написать прогу для телефона для отправки СМС и редактирования справочника, а функция которая точно работает пол километра текста занимает и то не всё вбил туда. я ведь тока начинающий. вот примеры.

Код

function AnsiToUcs(Convert:string):string;
var
 f:string;
 i:integer;
begin
 result:='';
 for i:=1 to Length(Convert) do begin
    f:=Convert[i];
if f='А' then result:=result+'0410';
if f='Б' then result:=result+'0411';
if f='В' then result:=result+'0412';
if f='Г' then result:=result+'0413';
if f='Д' then result:=result+'0414';
if f='Е' then result:=result+'0415';
if f='Ж' then result:=result+'0416';
if f='З' then result:=result+'0417';
if f='И' then result:=result+'0418';
if f='Й' then result:=result+'0419';
if f='К' then result:=result+'041A';
if f='Л' then result:=result+'041B';
if f='М' then result:=result+'041C';
if f='Н' then result:=result+'041D';
if f='О' then result:=result+'041E';
if f='П' then result:=result+'041F';
if f='Р' then result:=result+'0420';
if f='С' then result:=result+'0421';
if f='Т' then result:=result+'0422';
if f='У' then result:=result+'0423';
if f='Ф' then result:=result+'0424';
if f='Х' then result:=result+'0425';
if f='Ц' then result:=result+'0426';
if f='Ч' then result:=result+'0427';
if f='Ш' then result:=result+'0428';
if f='Щ' then result:=result+'0429';
if f='Ъ' then result:=result+'042A';
if f='Ы' then result:=result+'042B';
if f='Ь' then result:=result+'042C';
if f='Э' then result:=result+'042D';
if f='Ю' then result:=result+'042E';
if f='Я' then result:=result+'042F';
if f='а' then result:=result+'0430';
if f='б' then result:=result+'0431';
if f='в' then result:=result+'0432';
if f='г' then result:=result+'0433';
if f='д' then result:=result+'0434';
if f='е' then result:=result+'0435';
if f='ж' then result:=result+'0436';
if f='з' then result:=result+'0437';
if f='и' then result:=result+'0438';
if f='й' then result:=result+'0439';
if f='к' then result:=result+'043A';
if f='л' then result:=result+'043B';
if f='м' then result:=result+'043C';
if f='н' then result:=result+'043D';
if f='о' then result:=result+'043E';
if f='п' then result:=result+'043F';
if f='р' then result:=result+'0440';
if f='с' then result:=result+'0441';
if f='т' then result:=result+'0442';
if f='у' then result:=result+'0443';
if f='ф' then result:=result+'0444';
if f='х' then result:=result+'0445';
if f='ц' then result:=result+'0446';
if f='ч' then result:=result+'0447';
if f='ш' then result:=result+'0448';
if f='щ' then result:=result+'0449';
if f='ъ' then result:=result+'044A';
if f='ы' then result:=result+'044B';
if f='ь' then result:=result+'044C';
if f='э' then result:=result+'044D';
if f='ю' then result:=result+'044E';
if f='я' then result:=result+'044F';
if f='Ё' then result:=result+'0401';
if f='ё' then result:=result+'0451';
if f='.' then result:=result+'002E';
if f=',' then result:=result+'002C';
if f='!' then result:=result+'0021';
if f='"' then result:=result+'0022';
if f='№' then result:=result+'2116';
if f=';' then result:=result+'003B';
if f='%' then result:=result+'0025';
if f=':' then result:=result+'003A';
if f='?' then result:=result+'003F';
if f='*' then result:=result+'002A';
if f='(' then result:=result+'0028';
if f=')' then result:=result+'0029';
if f='/' then result:=result+'002F';
if f='0' then result:=result+'0030';
if f='1' then result:=result+'0031';
if f='2' then result:=result+'0032';
if f='3' then result:=result+'0033';
if f='4' then result:=result+'0034';
if f='5' then result:=result+'0035';
if f='6' then result:=result+'0036';
if f='7' then result:=result+'0037';
if f='8' then result:=result+'0038';
if f='9' then result:=result+'0039';
if f='+' then result:=result+'002B';
if f='-' then result:=result+'002D';
if f='=' then result:=result+'003D';
if f=',' then result:=result+'2C00';
if f=' ' then result:=result+'0020';
if f='A' then result:=result+'4100';
if f='B' then result:=result+'4200';
if f='C' then result:=result+'4300';
if f='D' then result:=result+'4400';
if f='E' then result:=result+'4500';
if f='F' then result:=result+'4600';
if f='G' then result:=result+'4700';
if f='H' then result:=result+'4800';
if f='I' then result:=result+'4900';
if f='J' then result:=result+'4A00';
if f='K' then result:=result+'4B00';
if f='L' then result:=result+'4C00';
if f='M' then result:=result+'4D00';
if f='N' then result:=result+'4E00';
if f='O' then result:=result+'4F00';
if f='P' then result:=result+'5000';
if f='Q' then result:=result+'5100';
if f='R' then result:=result+'5200';
if f='S' then result:=result+'5300';
if f='T' then result:=result+'5400';
if f='U' then result:=result+'5500';
if f='V' then result:=result+'5600';
if f='W' then result:=result+'5700';
if f='X' then result:=result+'5800';
if f='Y' then result:=result+'5900';
if f='Z' then result:=result+'5A00';
if f='a' then result:=result+'6100';
if f='b' then result:=result+'6200';
if f='c' then result:=result+'6300';
if f='d' then result:=result+'6400';
if f='e' then result:=result+'6500';
if f='f' then result:=result+'6600';
if f='g' then result:=result+'6700';
if f='h' then result:=result+'6800';
if f='i' then result:=result+'6900';
if f='j' then result:=result+'6A00';
if f='k' then result:=result+'6B00';
if f='l' then result:=result+'6C00';
if f='m' then result:=result+'6D00';
if f='n' then result:=result+'6E00';
if f='o' then result:=result+'6F00';
if f='p' then result:=result+'7000';
if f='q' then result:=result+'7100';
if f='r' then result:=result+'7200';
if f='s' then result:=result+'7300';
if f='t' then result:=result+'7400';
if f='u' then result:=result+'7500';
if f='v' then result:=result+'7600';
if f='w' then result:=result+'7700';
if f='x' then result:=result+'7800';
if f='y' then result:=result+'7900';
if f='z' then result:=result+'7A00';
  end;
end;

function UcsToAnsi(Convert:string):string;
var
 f:string;
 i:integer;
begin
 result:='';
 for i:=1 to Length(Convert)div 4 do begin
 f:=Copy(Convert,1,4);
 Delete(Convert,1,4);
if f='0410' then result:=result+'А';
if f='0411' then result:=result+'Б';
if f='0412' then result:=result+'В';
if f='0413' then result:=result+'Г';
if f='0414' then result:=result+'Д';
if f='0415' then result:=result+'Е';
if f='0416' then result:=result+'Ж';
if f='0417' then result:=result+'З';
if f='0418' then result:=result+'И';
if f='0419' then result:=result+'Й';
if f='041A' then result:=result+'К';
if f='041B' then result:=result+'Л';
if f='041C' then result:=result+'М';
if f='041D' then result:=result+'Н';
if f='041E' then result:=result+'О';
if f='041F' then result:=result+'П';
if f='0420' then result:=result+'Р';
if f='0421' then result:=result+'С';
if f='0422' then result:=result+'Т';
if f='0423' then result:=result+'У';
if f='0424' then result:=result+'Ф';
if f='0425' then result:=result+'Х';
if f='0426' then result:=result+'Ц';
if f='0427' then result:=result+'Ч';
if f='0428' then result:=result+'Ш';
if f='0429' then result:=result+'Щ';
if f='042A' then result:=result+'Ъ';
if f='042B' then result:=result+'Ы';
if f='042C' then result:=result+'Ь';
if f='042D' then result:=result+'Э';
if f='042E' then result:=result+'Ю';
if f='042F' then result:=result+'Я';
if f='0430' then result:=result+'а';
if f='0431' then result:=result+'б';
if f='0432' then result:=result+'в';
if f='0433' then result:=result+'г';
if f='0434' then result:=result+'д';
if f='0435' then result:=result+'е';
if f='0436' then result:=result+'ж';
if f='0437' then result:=result+'з';
if f='0438' then result:=result+'и';
if f='0439' then result:=result+'й';
if f='043A' then result:=result+'к';
if f='043B' then result:=result+'л';
if f='043C' then result:=result+'м';
if f='043D' then result:=result+'н';
if f='043E' then result:=result+'о';
if f='043F' then result:=result+'п';
if f='0440' then result:=result+'р';
if f='0441' then result:=result+'с';
if f='0442' then result:=result+'т';
if f='0443' then result:=result+'у';
if f='0444' then result:=result+'ф';
if f='0445' then result:=result+'х';
if f='0446' then result:=result+'ц';
if f='0447' then result:=result+'ч';
if f='0448' then result:=result+'ш';
if f='0449' then result:=result+'щ';
if f='044A' then result:=result+'ъ';
if f='044B' then result:=result+'ы';
if f='044C' then result:=result+'ь';
if f='044D' then result:=result+'э';
if f='044E' then result:=result+'ю';
if f='044F' then result:=result+'я';
if f='0401' then result:=result+'Ё';
if f='0451' then result:=result+'ё';
if f='002E' then result:=result+'.';
if f='002C' then result:=result+',';
if f='0021' then result:=result+'!';
if f='0022' then result:=result+'"';
if f='2116' then result:=result+'№';
if f='003B' then result:=result+';';
if f='0025' then result:=result+'%';
if f='003A' then result:=result+':';
if f='003F' then result:=result+'?';
if f='002A' then result:=result+'*';
if f='0028' then result:=result+'(';
if f='0029' then result:=result+')';
if f='002F' then result:=result+'/';
if f='0030' then result:=result+'0';
if f='0031' then result:=result+'1';
if f='0032' then result:=result+'2';
if f='0033' then result:=result+'3';
if f='0034' then result:=result+'4';
if f='0035' then result:=result+'5';
if f='0036' then result:=result+'6';
if f='0037' then result:=result+'7';
if f='0038' then result:=result+'8';
if f='0039' then result:=result+'9';
if f='002B' then result:=result+'+';
if f='002D' then result:=result+'-';
if f='003D' then result:=result+'=';
if f='2C00' then result:=result+',';
if f='0020' then result:=result+' ';
if f='4100' then result:=result+'A';
if f='4200' then result:=result+'B';
if f='4300' then result:=result+'C';
if f='4400' then result:=result+'D';
if f='4500' then result:=result+'E';
if f='4600' then result:=result+'F';
if f='4700' then result:=result+'G';
if f='4800' then result:=result+'H';
if f='4900' then result:=result+'I';
if f='4A00' then result:=result+'J';
if f='4B00' then result:=result+'K';
if f='4C00' then result:=result+'L';
if f='4D00' then result:=result+'M';
if f='4E00' then result:=result+'N';
if f='4F00' then result:=result+'O';
if f='5000' then result:=result+'P';
if f='5100' then result:=result+'Q';
if f='5200' then result:=result+'R';
if f='5300' then result:=result+'S';
if f='5400' then result:=result+'T';
if f='5500' then result:=result+'U';
if f='5600' then result:=result+'V';
if f='5700' then result:=result+'W';
if f='5800' then result:=result+'X';
if f='5900' then result:=result+'Y';
if f='5A00' then result:=result+'Z';
if f='6100' then result:=result+'a';
if f='6200' then result:=result+'b';
if f='6300' then result:=result+'c';
if f='6400' then result:=result+'d';
if f='6500' then result:=result+'e';
if f='6600' then result:=result+'f';
if f='6700' then result:=result+'g';
if f='6800' then result:=result+'h';
if f='6900' then result:=result+'i';
if f='6A00' then result:=result+'j';
if f='6B00' then result:=result+'k';
if f='6C00' then result:=result+'l';
if f='6D00' then result:=result+'m';
if f='6E00' then result:=result+'n';
if f='6F00' then result:=result+'o';
if f='7000' then result:=result+'p';
if f='7100' then result:=result+'q';
if f='7200' then result:=result+'r';
if f='7300' then result:=result+'s';
if f='7400' then result:=result+'t';
if f='7500' then result:=result+'u';
if f='7600' then result:=result+'v';
if f='7700' then result:=result+'w';
if f='7800' then result:=result+'x';
if f='7900' then result:=result+'y';
if f='7A00' then result:=result+'z';
  end;
end;

А надо бы покороче бы.

Это сообщение отредактировал(а) Girder - 6.6.2005, 13:35
PM MAIL   Вверх
Dynamic
Дата 6.6.2005, 09:18 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Опытный
**


Профиль
Группа: Участник
Сообщений: 372
Регистрация: 5.7.2004
Где: Салехард

Репутация: 12
Всего: 15



Цитата(Vovanmail @ 5.6.2005, 17:02)
Result := Result + IntToHex(Low(USC) + Ord(Convert[i])-Ord('à')) + Delim;
ругается на это

Как ругается? Напиши вместо Ord('à') код 224, т.е.
Код

Ord(Convert[i])-224 + Delim;

У меня компилится и работает нормально.



--------------------
Было бы о чем молчать, а уж что сказать – всегда найдется...
PM MAIL WWW   Вверх
Dynamic
Дата 6.6.2005, 11:21 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Опытный
**


Профиль
Группа: Участник
Сообщений: 372
Регистрация: 5.7.2004
Где: Салехард

Репутация: 12
Всего: 15



Ну вот тебе покороче:
Код

type
    TUCSCode = $0410..$7A00;
const
     AllChars = 'АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыьэюя'+
                #168#184'.,!"№;%:?*()/0123456789+-=, '+
                'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';

function AnsiToUcs(const Convert:string):string;
var i, ofs: integer;
begin
     Result := '';
     for i := 1 to Length(Convert) do
     begin
       ofs := AnsiPos(Convert[i], AllChars);
       if ofs > 0 then
        Result := Result + IntToHex(Low(TUCSCode) + ofs - 1, 4);
     end;
end;

function UcsToAnsi(const Convert:string):string;
var i, c: integer;
begin
     Result := '';
     i := 1;
     while i <= Length(Convert) do
     begin
       c := StrToIntDef('$'+ Copy(Convert, i, 4), -1);
       if (c >= Low(TUCSCode)) and (c <= High(TUCSCode)) then
        Result := Result + AllChars[c - Low(TUCSCode) + 1];
       inc(i, 4);
     end;
end;

procedure TForm1.Button2Click(Sender: TObject);
var s: string;
begin
     s := 'а б в г д е ё ж з и й к л м н';
     s := AnsiToUcs(s);
     ShowMessage(s);
     s := UcsToAnsi(s);
     ShowMessage(s);
end;

Добавлено @ 11:25
Только у тебя на 2С00 и на 002С стоят 2 запятые, так надо, что ли??


--------------------
Было бы о чем молчать, а уж что сказать – всегда найдется...
PM MAIL WWW   Вверх
Vovanmail
Дата 6.6.2005, 14:44 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Новичок



Профиль
Группа: Участник
Сообщений: 7
Регистрация: 5.6.2005

Репутация: нет
Всего: нет



Dynamic smile Это видать я маху дал, лучше наверное дал бы, шутка. Благодарствую тебе.
PM MAIL   Вверх
Guest
Дата 22.11.2005, 10:51 (ссылка)    |    (голосов: 0) Загрузка ... Загрузка ... Быстрая цитата Цитата


Unregistered











Код

function UCSToAnsi(s:string):string;

 function FMT(C:string):Char;
 var i:integer;
 begin
  i := StrToIntDef('$'+C,0);
  case i of
   1040..1103: i := i - 848;
   1105      : i := 184;
  end;
  Result := Chr(i);
 end;

var C:integer;
    I:integer;
begin
 Result := '';
 C := Length(S) div 4;
 For i:=0 to C-1 do
  Result := Result + FMT(Copy(S,i*4+1,4));
end;

function AnsitoUCS(S:string):string;

 function FMT(C:Char):string;
 var i:integer;
 begin
  Result := '';
  i := ord(C);
  case i of
   192..255 : i := i + 848;
   184      : i := 1105;
  end;
  result := inttohex(i,4)
 end;

var C:integer;
    I:integer;
begin
 Result := '';
 C := Length(S);
 For i:=1 to C do
  Result := Result + FMT(S[i]);
end;

  Вверх
  
Ответ в темуСоздание новой темы Создание опроса
Правила форума "Delphi: Общие вопросы"
SnowyMetalFan
bemsPoseidon
Rrader

Запрещается!

1. Публиковать ссылки на вскрытые компоненты

2. Обсуждать взлом компонентов и делиться вскрытыми компонентами

  • Литературу по Дельфи обсуждаем здесь
  • Действия модераторов можно обсудить здесь
  • С просьбами о написании курсовой, реферата и т.п. обращаться сюда
  • Вопросы по реализации алгоритмов рассматриваются здесь
  • 90% ответов на свои вопросы можно найти в DRKB (Delphi Russian Knowledge Base) - крупнейшем в рунете сборнике материалов по Дельфи


Если Вам понравилась атмосфера форума, заходите к нам чаще! С уважением, Snowy, MetalFan, bems, Poseidon, Rrader.

 
0 Пользователей читают эту тему (0 Гостей и 0 Скрытых Пользователей)
0 Пользователей:
« Предыдущая тема | Delphi: Общие вопросы | Следующая тема »


 




[ Время генерации скрипта: 0.0955 ]   [ Использовано запросов: 22 ]   [ GZIP включён ]


Реклама на сайте     Информационное спонсорство

 
По вопросам размещения рекламы пишите на vladimir(sobaka)vingrad.ru
Отказ от ответственности     Powered by Invision Power Board(R) 1.3 © 2003  IPS, Inc.