472,971 Members | 1,862 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,971 software developers and data experts.

How do i convert unicode string to ansi string in C#?


Hi,
I need to convert unicode string to ansi string

Thanks in adavance.
Nov 17 '05 #1
4 79339
use System.Text.Encoding.Convert static method..

--

Thanks,
Yunus Emre ALPÖZEN
BSc, MCSD.NET

"Julia" <co********@012.net.il> wrote in message
news:uO**************@TK2MSFTNGP10.phx.gbl...

Hi,
I need to convert unicode string to ansi string

Thanks in adavance.

Nov 17 '05 #2
Julia <co********@012.net.il> wrote:
I need to convert unicode string to ansi string


All strings in .NET are Unicode already - there's no such thing as an
ANSI string within .NET. If you need a string encoded into a byte array
as ANSI, you need Encoding.GetBytes.

See http://www.pobox.com/~skeet/csharp/unicode.html for more
information.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #3
"Julia" <co********@012.net.il> wrote in message
news:uO**************@TK2MSFTNGP10.phx.gbl...
I need to convert unicode string to ansi string


http://www.classdotnet.com/ioCsExamples.html
Nov 17 '05 #4
Mark Rae <ma**@mark-N-O-S-P-A-M-rae.co.uk> wrote:
"Julia" <co********@012.net.il> wrote in message
news:uO**************@TK2MSFTNGP10.phx.gbl...
I need to convert unicode string to ansi string


http://www.classdotnet.com/ioCsExamples.html


I hate to say it, but the code on there is pretty awful.

Save byte array to a binary file:
1) No "using" statement to close the file if anything goes wrong.
(It may seem picky to state this for every example, but it's really,
really important.)
2) There's no need for a binary writer if you're just saving a byte
array! Just use Stream.Write.

Read a file into a byte array:
1) Again, no using statement
2) Again, no need for a binary reader
3) Assumes file length doesn't change after finding out length
See http://www.pobox.com/~skeet/csharp/readbinary.html for better code

Write ANSI strings to a text file:
1) No "using" statement
2) Doesn't use ANSI! Uses UTF-8 (the default encoding for StreamWriter)

Read UTF-8 file and display in textbox
1) No using statement
2) No need to explicitly use UTF-8 when that's the default!
3) Loading a file in the UI thread is a bad idea. Why even
bother making the example a GUI one? (The name of the method
is pretty terrible too.)

Writer string to UTF-8 encoded file:
1) No using statement
2) Again, why explicitly state UTF-8? (If it's because the
property is different from the version used by default,
that should be very clearly commented.)

Write Unicode File:
1) No using statement
2) Again, uses UI property while doing file IO. Generally not
a good idea, and again not needed for the example.

Seeking etc
1) No using statement
2) I far prefer the Position property to calling Seek when you're going
to a specific place in the file. I think it's much clearer. That's
possibly just me though.
3) Comment for calling Stream.Read says that 100 bytes are read, when
actually *up to* 100 bytes are read. This should be at least
mentioned, as it's the cause of frequent problems. At least the
return value is stored in a variable...

Copy a file
1) Again, IO in a UI thread...
2) What's wrong with a straight call to File.Copy?

Move/Rename, and Delete
See problems with copy

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Morten Overgaard | last post by:
Hi How do I convert a managed System::String to a CString. I need to handle unicode characters ( Japan and Chinese ) as well as "normal" ANSI characters. I have tried the following char* p...
3
by: nicksop | last post by:
How Can I convert ANSI to OEM with StreamWriter ?
5
by: Terry Olsen | last post by:
Looking for info on how to convert a byte array to a string, and string to byte array. Thanks.
2
by: Clay | last post by:
I need to convert a unicode string to an ansi string. This should not be difficult but I simply cannot find a way to do this. Anyone?
1
by: recover | last post by:
#include <xxx> int main() { const wchar* pwcHello=L"hello"; char* pcHello; xxxxxx //do something using stl cout<<pcHello<<endl; } =============out===========
1
codexparse
by: codexparse | last post by:
I am writing a browser program in C++ Builder 6 that loads a web page using the following code: void __fastcall TForm1::ToolButton1Click(TObject *Sender) { wchar_t buff; ...
4
by: Peter | last post by:
Does anyone know how to convert the following VB6 code to C# code? Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (dest As Any, Source As Any, ByVal bytes As Long) Dim...
3
by: =?iso-8859-1?B?S2VyZW0gR/xtcvxrY/w=?= | last post by:
Hi, i have a byte that holds a bunch of data of type REG_MULTI_SZ in UNICODE,. I must convert this byte to a REG_MULTI_SZ in ANSI code. How can i do this,...? TIA,... Regards
7
by: firepol | last post by:
Hello there, I am dealing with files encoded in UTF8 and I can't find a way to convert them into ANSI. I've already searched in google for this since a while, and I'm not achieving the result I...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
3
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.