Page 1 of 1

Proper way to force char array to type 80?

Posted: Fri Sep 10, 2010 2:43 pm
by paulmansour
Hi,

In the Unicode version, I have a character array (a simple matrix). I want to force it to type 80, no matter what type is in it. I have this so far:

Code: Select all

     {
       80=⎕DR ⍵:⍵
       r←⍵
       b←,255≤⎕UCS r
       (b/,r)←'?'
       r[⍳↑⍴r;]
      }

Is there a better way to do this? to force compaction?

Thanks

Re: Proper way to force char array to type 80?

Posted: Fri Sep 10, 2010 3:14 pm
by Phil Last
      {⎕UCS⊃63 ⍵+.×1 0=⊂256≤⍵}∘⎕UCS

Not quicker, in fact it takes nearly twice as long, but it looks nicer.

Re: Proper way to force char array to type 80?

Posted: Tue Sep 21, 2010 8:28 am
by Morten|Dyalog
This is slightly faster... And "nicer" according to my taste:

{⎕IO←0 ⋄ ((⎕UCS⍳256),'?')[256⌊⎕UCS ⍵]}

I think there is a bug in your function; it folds UCS 255 (ÿ) to ? if the argument has type 160, but not if the type is already 80.

Re: Proper way to force char array to type 80?

Posted: Tue Sep 21, 2010 9:08 am
by Phil Last
Morten|Dyalog wrote:I think there is a bug in your function; it folds UCS 255 (ÿ) to ? if the argument has type 160, but not if the type is already 80.


Yes it's

      b←,255≤⎕UCS r

that should be 256. ' wasn't going to mention it.