473,700 Members | 2,610 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

A simple question - how to convert from UTF8 to wide char (wchar_t) on linux

Hi,

I need to convert a string from UTF8 to wide character (wchar_t *). I
perform the same in windows using:

MultiByteToWide Char(CP_UTF8, 0, pInput, -1, pOutput, nLen);

However, in linux this API is not available. However, there exists
mbstowcs() API, which converts multibyte string to wide character. But
will this API convert UTF8 encoded string to wide character? Or this
API will convert *only ASCII* characters to wide characters?

There exists also iconv() API which converts characterset using a
characterset conversion descriptor returned by iconv_open(). But for
iconv_open(char *toCode, char* fromCode), what would be "toCode" and
"fromCode" value? I think "toCode" will be UTF8, but what would be
"fromCode"?
Thanks and regards,
- Uday

Jun 6 '06 #1
4 22029
ud******@gmail. com wrote:
Hi,

I need to convert a string from UTF8 to wide character (wchar_t *). I
perform the same in windows using:

MultiByteToWide Char(CP_UTF8, 0, pInput, -1, pOutput, nLen);

However, in linux this API is not available. However, there exists
mbstowcs() API, which converts multibyte string to wide character. But
will this API convert UTF8 encoded string to wide character? Or this
API will convert *only ASCII* characters to wide characters?

There exists also iconv() API which converts characterset using a
characterset conversion descriptor returned by iconv_open(). But for
iconv_open(char *toCode, char* fromCode), what would be "toCode" and
"fromCode" value? I think "toCode" will be UTF8, but what would be
"fromCode"?
Thanks and regards,
- Uday

Your fromCode is UTF8 and your toCode is WCHAR_T.

Robert
Jun 6 '06 #2
You need to set tocode to "UTF-8" and fromcode to "WCHAR_T"
To get a complete list for to and from do 'iconv --list'

ud******@gmail. com wrote:
Hi,

I need to convert a string from UTF8 to wide character (wchar_t *). I
perform the same in windows using:

MultiByteToWide Char(CP_UTF8, 0, pInput, -1, pOutput, nLen);

However, in linux this API is not available. However, there exists
mbstowcs() API, which converts multibyte string to wide character. But
will this API convert UTF8 encoded string to wide character? Or this
API will convert *only ASCII* characters to wide characters?

There exists also iconv() API which converts characterset using a
characterset conversion descriptor returned by iconv_open(). But for
iconv_open(char *toCode, char* fromCode), what would be "toCode" and
"fromCode" value? I think "toCode" will be UTF8, but what would be
"fromCode"?
Thanks and regards,
- Uday


Jun 6 '06 #3
Oops .. sorry for my foolish swap in my previous post ..

Set fromcode to "UTF-8" and tocode to "WCHAR_T"

ithink wrote:
You need to set tocode to "UTF-8" and fromcode to "WCHAR_T"
To get a complete list for to and from do 'iconv --list'

ud******@gmail. com wrote:
Hi,

I need to convert a string from UTF8 to wide character (wchar_t *). I
perform the same in windows using:

MultiByteToWide Char(CP_UTF8, 0, pInput, -1, pOutput, nLen);

However, in linux this API is not available. However, there exists
mbstowcs() API, which converts multibyte string to wide character. But
will this API convert UTF8 encoded string to wide character? Or this
API will convert *only ASCII* characters to wide characters?

There exists also iconv() API which converts characterset using a
characterset conversion descriptor returned by iconv_open(). But for
iconv_open(char *toCode, char* fromCode), what would be "toCode" and
"fromCode" value? I think "toCode" will be UTF8, but what would be
"fromCode"?
Thanks and regards,
- Uday


Jun 6 '06 #4
Thanks a lot for your prompt help. I have following 2 questions:

1. Will "WCHAR_T" be platform independent? Going forward I plan to
deploy the piece of code on Solaris 10.
2. When converting using iconv(), how can I determine the size required
for output string? "iconv(3)" man page does not tell about anything
about it.
size_t retval = iconv(cd, pInput, wcslen(pInput), pOutput,
???);
Do I have to calculate it by myself? Or there is any platform API that
I can use for my purpose.

Thanks again,
- Uday

Jun 6 '06 #5

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

Similar topics

1
3160
by: ajay.sonawane | last post by:
How can I find the wheather the occurance substring is main string in wide char provided that the compasion should be case insensitive.
5
4333
by: sarab | last post by:
Hi, I have a managed C++ app in which i need to convert String * to char *. How can i achive this?. regards -sarab
4
42884
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
5
6783
by: tienlx | last post by:
Hi all, I'm have a problem that i don't know how to convert object to char in C# . Does anybody know ? Thanks.
5
5380
by: Neo | last post by:
how convert CString to char *? regards, Mohammad Omer Nasir
0
1807
by: Bipin Mistry | last post by:
Hello all, I an new to XML read-write, and I am using "LibXml2" to work around with XML data. I am having 2 task to do (development in c++ using libxml2-2.6.24.win32) 1. To read & parse XML data received in the form of char * 2. To create char * from the row data I have in my own created structure that I am porting to xmlDocPtr type.
1
12691
by: Hooyoo | last post by:
I read the content from a file encoded with UTF8 like this: byte data = binaryReader.ReadBytes(file.Length); And next step, I want to transform data to ASCII format, How can I do this? You know, Using Encoding.UTF8.GetString(data) can get a ASCII string, but I need a byte. I hope you get my point. Any suggestion will be appreciated.
1
1741
by: vcxpert | last post by:
Hi, I want to use ExtTextOutW function without using UNICODE preprocesser defined as rest piece of my code doesn't deal with wide char... So how can i use Such functions without declaring UNICODE .???? Regards VCXPERT
8
4792
by: AGRAJA | last post by:
how to convert unsigned to char? Ref: http://www.thescripts.com/forum/thread477545.html how do I print without the leading ffffff (yet the result should be char*)?
0
8725
marktang
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...
0
8644
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,...
0
9074
jinu1996
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...
1
8970
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,...
0
7807
agi2029
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...
0
4403
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...
1
3088
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2392
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2027
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.