How do I convert a Byte array (unsigned char managed) to a
char array(unmanaged ) with wide character taken into
account?
Nov 16 '05
15 34602
System::Char can store both unicode as well as single byte characters.
--
Regards,
Nish [VC++ MVP]
"Kueishiong Tu" <ks****@seed.ne t.tw> wrote in message
news:3c******** *************** *****@phx.gbl.. . -----Original Message----- There was en error in my prev post.
char is 8 bits (a byte) and Char is 16 bits (2 bytes)
Does the 2-byte Char have a fixed length or it can adjust to the data depending on what are stored (may be one-byte or two-byte)? By the way, do you know a convert routine that can convert a Byte array to a Big-5 char array (a mixture of one-byte and two-byte characers)?
regards, Kueishiong Tu -----Original Message----- Hmmm
Okay I think one of the following is what you want :-
//this is to obtain a single byte char array //might lose chinese characters
char smallarray[512]; for(int i=0; i<barray->Length; i++) smallarray[i] = barray[i];
//this gets a wide char array String* tmp = new String(Encoding ::ASCII->GetChars
(barray));__wchar_t* array = (__wchar_t*)
Marshal::String ToHGlobalUni( tmp).ToPointer( ); //... // You can now use array (wide char array) //... Marshal::FreeC oTaskMem(array) ;
I think the second one is what you want. Please try it
out and see if itworks for you.
-- Regards, Nish [VC++ MVP]
The problem I have is that the decoding routine (already
available) expects the input to be a char array instead
of a wide char array. How do I get around this?
Does VC++ .net has the concept of locality so that you
have to set up the locality properly before it will
recognize the local language (something like sun solaris)?
I think this is done implicitly in Microsoft products.
Kueishiong Tu
I have found the solution to my problem. And the solution
is surprising easy. It is
Byte a[100];
char b[100];
for(int i=0; i<a->Length; i++)
{
b[i] = (char) a[i];
}
The resulting char array then works fine for both 1-byte
character and 2-byte character.
Considering that a Byte array *cannot* contain 2-byte characters, the last
sentence about how it's fine for both 1-byte and 2-byte characters is a moot
point
--
Regards,
Nish [VC++ MVP]
"Kueishiong Tu" <ks****@seed.ne t.tw> wrote in message
news:18******** *************** *****@phx.gbl.. . I have found the solution to my problem. And the solution is surprising easy. It is
Byte a[100]; char b[100];
for(int i=0; i<a->Length; i++) { b[i] = (char) a[i]; }
The resulting char array then works fine for both 1-byte character and 2-byte character.
Considering that a Byte array *cannot* contain 2-byte characters, the last
sentence about how it's fine for both 1-byte and 2-byte characters is a moot
point
--
Regards,
Nish [VC++ MVP]
"Kueishiong Tu" <ks****@seed.ne t.tw> wrote in message
news:18******** *************** *****@phx.gbl.. . I have found the solution to my problem. And the solution is surprising easy. It is
Byte a[100]; char b[100];
for(int i=0; i<a->Length; i++) { b[i] = (char) a[i]; }
The resulting char array then works fine for both 1-byte character and 2-byte character.
memcpy is probably faster.
"Nishant S" <ni**@nospam.as ianetindia.com> wrote in message
news:uM******** *****@TK2MSFTNG P12.phx.gbl... Considering that a Byte array *cannot* contain 2-byte characters, the last sentence about how it's fine for both 1-byte and 2-byte characters is a
moot point
-- Regards, Nish [VC++ MVP] "Kueishiong Tu" <ks****@seed.ne t.tw> wrote in message news:18******** *************** *****@phx.gbl.. . I have found the solution to my problem. And the solution is surprising easy. It is
Byte a[100]; char b[100];
for(int i=0; i<a->Length; i++) { b[i] = (char) a[i]; }
The resulting char array then works fine for both 1-byte character and 2-byte character.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: spammersarevermin |
last post by:
I'm testing a VoIP application, and I can't figure out how to dump
this into a Udpclient.send function. Thanks for any help, pointers...
How do I convert the array below to VB.NET? --
unsigned char grq = {
0x03, 0x20, 0x00, 0x00, 0x06, 0x00, 0x08, 0x91, 0x4a,
0x00,
0x02, 0x00, 0x0a, 0x60, 0x86, 0x48, 0x01, 0x86, 0xf8,
0x72,
|
by: Trep |
last post by:
Hi there!
I've been having a lot of difficult trying to figure out a way to convert
a terminated char array to a system::string for use in Visual C++ .NET
2003.
This is necessary because I have some legcay C code that needs to process
a string taken from a textbox, then I need to re-display the string as the
textbox->Text. I easily found how to convert from system::string to char
but I can't figure out how to go the other way!!
|
by: AlexFarokhyans |
last post by:
Hello,
I'm trying to convert String to Char array. I'm getting a string from
user input text box and then I have char firstName.
I need to convert the string that is in the text box to
firstName.
Thank you
|
by: Goran |
last post by:
Hi!
I need to convert from a unsigned char array to a float. I don't think
i get the right results in the program below.
unsigned char array1 = { 0xde, 0xc2, 0x44, 0x23}; //I'm not sure in
what order the data is stored so i try both ways.
unsigned char array2 = { 0x23, 0x44, 0xc2, 0xde};
float *pfloat1, *pfloat2;
|
by: vsk |
last post by:
Hai,
I need to know how to convert an unsigned char array into hexstring.
can anyone help me in this regard?.
Thanks.
| |
by: John Smith |
last post by:
Hello,
Suppose I have the following C# code which I want to convert to VB:
for (int i = 0; i < nFieldLength; i++)
Console.Write((char) sValue);
sValue is a byte array.
The problem is the typecast which I can't find an equivalent for in VB. I
|
by: Man4ish |
last post by:
HI ,
I am trying to convert string into char array of characters.but facing problem.
#include <iostream>
#include <string>
using namespace std;
int main()
{
string t="1,2,3,4,5,6";
|
by: Brandon |
last post by:
How do I convert a string to a char array? I am doing this so I can edit
the string received from an sql query so I can remove unnecessary
characters.
|
by: deeas |
last post by:
hi
i receive bytes from server into microcontroller , how can i convert them to char
|
by: Lohith r |
last post by:
Hi Friends,
I have a serious and irritating problem, please help
mdContext->digest is an unsigned char Array with hexadecimal values so
for (i = 0; i < 16; i++)
printf ("%02x", mdContext->digest);
prints 900150983cd24fb0d6963f7d28e17f72
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
| |
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |