Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / January 2005

Tip: Looking for answers? Try searching our database.

International strings/chars

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dobieslaw Wroblewski - 31 Dec 2004 05:16 GMT
Hello,

Please help me. I think I found this once but cannot find again :-(

Is there any .NET framework class/method that returns the international
counterpart of a given string or character? For example - for '?' it returns
'o'.

DW.
Morten Wennevik - 31 Dec 2004 11:23 GMT
Hi Dobieslaw,

There isn't an easy way to do this, but this hack seem to work for most  
characters.

string s = "áàäãâåéèëêíìïîóòöõôøúùüûýÿ";
byte[] b = Encoding.GetEncoding(1251).GetBytes(s);
string t = Encoding.ASCII.GetString(b);

t == aaaaaaeeeeiiiioooooouuuuyy

Signature

Happy Coding!
Morten Wennevik [C# MVP]

Dobieslaw Wroblewski - 01 Jan 2005 11:24 GMT
> string s = "??????????????????????????";
> byte[] b = Encoding.GetEncoding(1251).GetBytes(s);
> string t = Encoding.ASCII.GetString(b);

Thanks, it works!

I believe I used Encoding.ASCII for writing to text files, but in such cases
I got question marks instead of the national characters - so this trick is
quite mysterious for me, but - goodie - it works :-).

DW.
Jon Skeet [C# MVP] - 01 Jan 2005 17:22 GMT
Dobieslaw Wroblewski
<dobieslaw.wroblewski@reverse_the_next.com.cegedim> wrote:
> > string s = "áàäãâåéèëêíìïîóòöõô=F8úùüûý?";
> > byte[] b = Encoding.GetEncoding(1251).GetBytes(s);
[quoted text clipped - 4 lines]
> I believe I used Encoding.ASCII for writing to text files, but in
> such cases I got question marks instead of the national characters -

Yes, you would - ASCII doesn't contain any accented characters.

> so this trick is
> quite mysterious for me, but - goodie - it works :-).

Unfortunately, the above isn't really guaranteed to work. The Encoding
class doesn't specify any behaviour for when GetString is presented
with bytes which aren't a valid encoded form for that encoding. It may
work now, but there's no guarantee it'll work in the future at all.

I suspect you want something like "normalizatino form D" of the Unicode
string, followed by a removal of all accents etc - but I don't know
enough about normalization to be sure, and I don't know of any
implementations of that for .NET :(

If you know that all the characters you care about are within a certain
range, I'd suggest a hand-crafted mapping.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Dobieslaw Wroblewski - 02 Jan 2005 01:36 GMT
> If you know that all the characters you care about are within a certain
> range, I'd suggest a hand-crafted mapping.

Well, that always could be done ;-). I just thought of something smarter.
And I think I saw some function for that, but now I cannot remember for sure
if this was .NET, Win32 API or... maybe even Java ;-).

DW.
Jon Skeet [C# MVP] - 02 Jan 2005 07:49 GMT
Dobieslaw Wroblewski
<dobieslaw.wroblewski@reverse_the_next.com.cegedim> wrote:
> > If you know that all the characters you care about are within a certain
> > range, I'd suggest a hand-crafted mapping.
>
> Well, that always could be done ;-). I just thought of something smarter.
> And I think I saw some function for that, but now I cannot remember for sure
> if this was .NET, Win32 API or... maybe even Java ;-).

I wouldn't be surprised if there were a call in Win32, and you may be
able to use P/Invoke to use that call. You could try asking in a
Windows internationalization newsgroup...

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.