PC Review


Reply
Thread Tools Rate Thread

Convert memoryStream to unicode string

 
 
=?Utf-8?B?RWRp?=
Guest
Posts: n/a
 
      25th Jul 2005
Hi,
Im using .Net 1.1 with Vs2003
Im trying to convert memorystream that im getting from
the clipboard into a unicode string ex.

//Set The clipboard data (unicode text file)....
StreamWriter sw = new StreamWriter(fileName, false, Encoding.Unicode);
sw.Write("Bla");
...
...
...

//Get the data from the clipboard
MemoryStream ms = dat.GetData( "Object Type" ) as System.IO.MemoryStream;

byte [] bytes = new byte[4096];
Encoding unicode = Encoding.Unicode;

while((count = ms.Read(bytes,0,4096)) > 0)
{
int result = unicode .GetCharCount(bytes, 0 ,count);
char [] chars = new char[result];
chars = unicode.GetChars(bytes, 0 , count);
//In This point the char array is not currect s.t unicode charecters are wrong
...
}

Same code is working fine with Encoding.ASCII
any known .Net 1.1 on this subject?

Thanks



 
Reply With Quote
 
 
 
 
Mattias Sjögren
Guest
Posts: n/a
 
      25th Jul 2005
>Im using .Net 1.1 with Vs2003
>Im trying to convert memorystream that im getting from
>the clipboard into a unicode string ex.


You should use the Encoding class that actually matches how the
characters are encoded in the clipboard stream. If ASCII works and
Unicode doesn't then clearly they are not stored as UTF-16.

The conversion to unicode happens in the GetChars call regardless
which encoding class you're using, since all strings and chars in .NET
ae stored as Unicode.



Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to convert a string to MemoryStream ad Microsoft C# .NET 4 14th Jul 2006 08:19 AM
in C# fastest way to convert a string into a MemoryStream Daniel Microsoft Dot NET 5 3rd Aug 2005 05:32 PM
in C# fastest way to convert a string into a MemoryStream Octavio Hernandez Microsoft C# .NET 2 3rd Aug 2005 07:38 AM
in C# fastest way to convert a string into a MemoryStream Daniel Microsoft Dot NET Framework 1 3rd Aug 2005 07:17 AM
How to convert this unicode string to a normal string? =?Utf-8?B?Tmlja3k=?= Microsoft C# .NET 2 21st Jun 2004 11:24 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:04 AM.