[DGD]Translating characters

E. Harte harte at xs4all.nl
Tue Dec 28 21:10:47 CET 1999


On Tue, 28 Dec 1999, Frantisek Fuka wrote:

> What is the fastest way to translate characters in DGD? I have long
> strings and I want to replace all specific characters (about 30) with
> different characters. For example if I have translation table
> ("iegs","1365"), I want "this is great test" to be translated as "th15
> 15 6r3at t35t".

I think the most straightforward one is the easiest:

[ Disclaimer: Untested code. ]

  string
  translate(string str)
  {
      int     i, sz;
      mapping m;

      m = ([ 'i': '1',
             'e': '3',
             'g': '6',
             's': '5' ]);
      for (i = 0, sz = strlen(str); i < sz; i++) {
          if (m[str[i]]) {
              str[i] = m[str[i]];
          }
      }
      return str;
  }

Hope that helps,

Erwin.
-- 
Erwin Harte  -  Forever September, 2310 and counting  -  harte at xs4all.nl


List config page:  http://list.imaginary.com/mailman/listinfo/dgd



More information about the DGD mailing list