Character recognition and output

Tyro ridimz at yahoo.com
Mon Nov 6 00:17:29 PST 2006


Wondering if someone can point me in the right direction on small
problem.

I'm attempting to parse(?) a file with the following
string "ÿÿÿÿÿÿÿÿÿÿÿÿÿ" embeded somewhere in it. When I try to
output the information, however, writef() chokes if it comes across
one of these characters. I thought that this was simply a writef
[doFormat] problem so I tried to read the file using Christopher
Miller's sample richtext viewer that accompanies DFL and the same
thing happens (Error: 4invalid UTF-8 sequence). I tried different
combinations of wchar[], dchar[], and byte[] but to no avail. How
do I fix this?

import std.stdio: emitln = writefln, emit = writef;
import std.file: exists, read;

void main (char[][] args)
{
  if (args.length == 2 && args[1].exists())
  {
    char[] file = cast(char[])args[1].read();
    foreach(sizendx, char ch; file)
    {
      try { emit(ch); }             // terminates on ÿ
      catch { emit(" ");continue; }
    }
  }
  else
    emit ("usage is: ids filename");
}

Andrew Edwards



More information about the Digitalmars-d-learn mailing list