List Info

Thread: extracting the n'th character of a widestring




extracting the n'th character of a widestring
user name
2007-01-25 05:24:16

I busy to convert characters within a widestring to an xml stream; However I encounter problems with 'special characters' e.g. the euro sign.

Searching for a solution, I did find within the about.delphi.com website:
About Unicode character sets

The ANSI character set used by Windows is a single-byte character set.
Unicode stores each character in the character set in 2 bytes instead
of 1. Some national languages use ideographic characters, which require
more than the 256 characters supported by ANSI. With 16-bit notation we
can represent 65,536 different characters. Indexing of multibyte
strings is not reliable, since s[i] represents the ith byte (not necessarily the i-th character) in s.

If you must use Wide characters, you should declare a string variable
to be of the WideString type and your character variable of the
WideChar type. If you want to examine a wide string one character at a
time, be sure to test for multibite characters. Delphi doesn't support
automatic type conversions betwwen Ansi and Wide string types.

Does anyone know how to extract the nth character of type widechar of a widestring?

My example:

var
Value : widestring;
begin
Value = '€';

examining this example will result in:

Value = '€' > TRUE
but
Value[1] = '€' FALSE

Conversing widestring character to xml format , i use:
'&#x' + IntToHex(LOrd, 4) + ';'
Parsing the variable Value
ord(value[1]) will result in 8364 and
ord(value) will result in 0080 ;

Any ideas will be welcomed.

Regards

Andries
The Netherlands

__________________________________________________________
Be a PS3 game guru.
Get your game face on with the latest PS3 news and previews at Yahoo! Games.
http://videogames.yahoo.com/platform?platform=120121

[Non-text portions of this message have been removed]

__._,_.___
.

__,_._,___
Re: extracting the n'th character of a widestring
user name
2007-01-25 06:44:08
Hi Andries, > var > Value : widestring; > begin > Value = '€'; > > examining this example will result in: > > Value = '€' > TRUE > but > Value[1] = '€' FALSE If you need to know it's at a certain position (like 1), I always do: if Pos('€',Value) = 1 then ... Which works just fine with WideStrings as well. > Andries > The Netherlands Groetjes, Bob Swart -- Bob Swart Training & Consultancy (eBob42.com) Forever Loyal to Delphi Blog: http://www.drbob42.com/blog - RSS: http://drbob42.com/weblog.xml New Delphi 2006 Courseware e-books at http://www.eBob42.com/courseware ----------------------------------------------------- Home page: http://groups.yahoo.com/group/delphi-en/ To unsubscribe: delphi-en-unsubscribe@yahoogroups.com Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/delphi-en/ <*> Your email settings: Individual Email | Traditional <*> To change settings online go to: http://groups.yahoo.com/group/delphi-en/join (Yahoo! ID required) <*> To change settings via email: mailto:delphi-en-digest@yahoogroups.com mailto:delphi-en-fullfeatured@yahoogroups.com <*> To unsubscribe from this group, send an email to: delphi-en-unsubscribe@yahoogroups.com <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/
[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )