fork download
  1. {$MODE Delphi}
  2. PROGRAM sms3;
  3.  
  4. VAR SMSText : String[160];
  5.  
  6. FUNCTION Text2Keys(const T : string[160]; const WithSeparator : boolean) : string;
  7. const Char2Phone : array['A'..'Z'] of string = ('2', '22', '222', '3', '33', '333', '4', '44', '444', '5', '55', '555', '6', '66', '666', '7', '77', '777', '7777', '8', '88', '888', '9', '99', '999', '9999');
  8. var i : integer;
  9. R : string;
  10. begin
  11. R := '';
  12. for i:=1 to length(T) do begin
  13. if (UpCase(T[i]) in ['A'..'Z']) then begin
  14. if (T[i] in ['A'..'Z']) then R := R + '#';
  15. R := R + Char2Phone[UpCase(T[i])]
  16. end else begin
  17. case T[i] of
  18. '0'..'9' : R := R + '$' + T[i];
  19. '.' : R := R + '1';
  20. ',' : R := R + '11';
  21. '!' : R := R + '111';
  22. '?' : R := R + '1111';
  23. ' ' : R := R + ' ';
  24. else R := R + '[?]';
  25. end;
  26. end;
  27. if WithSeparator and not(i = length(T)) then R := R + ';';
  28. end;
  29. Result := R;
  30. end;
  31.  
  32. BEGIN
  33. WriteLn('Texto da SMS?');
  34. ReadLn(SMSText);
  35. WriteLn('Sequencia de tecla do telemovel:');
  36. WriteLn(Text2Keys(SMSText, true));
  37. ReadLn; // pausa
  38. END.
Success #stdin #stdout 0.01s 256KB
stdin
Mensagem de exemplo, com testes de números, 123, e de MaiUsCulAs.
stdout
Texto da SMS?
Sequencia de tecla do telemovel:
#6;33;66;7777;2;4;33;6; ;3;33; ;33;99;33;6;7;555;666;11; ;222;666;6; ;8;33;7777;8;33;7777; ;3;33; ;66;[?];[?];6;33;777;666;7777;11; ;$1;$2;$3;11; ;33; ;3;33; ;#6;2;444;#88;7777;#222;88;555;#2;7777;1