Question
· Mar 9, 2017

How to convert perse unicode to unicode conversion

Please will correct the code:

    a is a perse Unicode to Unicode mapping value.Str=other status. It is how to convert English to french .

abcd
  s a=[192,194,196,199,201,200,202,203,206,207,212,214,217,219,220,215,224,226,228,231,233,232,234,235,238,239,244,246,249,251,252,247,193,195,197,198,208,209,222,223,204,205,210,211,172,216,174,221,225,227,229,230,240,241,254,255,236,237,242,243,188,248,190,253,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,222,191,224,225,226,227,228,213,218,231,232,233,234,235,236,237,190,239,240,241,242,243,244,245,250,247,248,249,250,251,252,253,254,255]
  f i=0:1:127 {
    s c= a."i"
    if $d(c) {
      s retval=a."i"
      if (c >= 128 && c <= 255) {
        s retval=a-128
      }
      return retval
    }
    return c
  }
  s str ="Other Status"
  if $d(str) {
    f k=1:1:$l(str) {
      s extract=$a($e(str,k))
      if (extract >= 128 && extract <= 255) {
        s value=$e(str,k)
        f j=i:1:$l(str) {
          w $translate(value(j),a)
        }                   
      }            
    }          
  }
Discussion (2)0
Log in or sign up to continue

I don't really understand the question. It sounds like you're trying to convert from one eight-bit character set to another, but French generally uses the same character set as English, as far as I know. If you're using a Unicode instance of Caché, your first resort should be I/O translation: translate the input to Unicode, then translate on output to the desired character set. Doing it in COS is slower and less convenient.

That said, here are some things in your code that don't really make sense:

  1. a."i"; should probably be a.%Get(i).
  2. a-128; maybe a.%Get(c-128)?
  3. I don't understand the purpose of the first loop or the return statements.
  4. value(j); ...?

If I were to hazard a guess at rewriting this, my first try might be something like this:

for i=1:1:$l(str) {
    s c=$e(str,i)
    if $a(c)<128) {
        w c
    } else {
        w $c(a.%Get($a(c)-128))
    }
}