[Mono-list] conversions

Jonathan Pryor jonpryor@vt.edu
Tue, 05 Oct 2004 06:32:13 -0400

On Tue, 2004-10-05 at 04:34, Polton, Richard (IT) wrote:
>  In fact, habing given it further thought, I have a couple of questions:
> i) if I sit at a Japanese terminal (for example) and enter '-', i.e.
> ichi or 'one', is this a valid Unicode character?


> ii) how wide is the 'char' datatype? I assume it contains Unicode rather
> than single-byte ASCII.

16-bit unsigned value.  It supports Unicode.

> iii) if entering 'ichi' is valid, and char contains Unicode, then I
> suspect that the below subtration will return a number substantially
> greater than one.

No.  At least, not if it's remotely like CVS HEAD:

	public static int Val (char Expression) {
		if (char.IsDigit(Expression)) {
			return Expression - '0';
		else {
			throw new ArgumentException();

Ichi isn't a digit, so it will generate an ArgumentException.

(Assuming that Ichi is Unicode U+4E00, which certainly looks like '-'. 
It's in the Unicode category "Letter, Other".)

The subtraction should be safe, as (1) it's only done on digits, and (2)
Unicode follows the ASCII character ordering (for glyphs 0-127), which
permits this subtraction.

 - Jon