473,406 Members | 2,336 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Unicode Characters Size

Expand|Select|Wrap|Line Numbers
  1. std::string str ="����������";
  2. std::cout<<str.length()<<std::endl;
  3.  

this code returns 20, hence each unicode character is considered as 4 bytes, but the same code in java returns 10, where each unicode character is considered as 2 bytes.

My Question why java and c++ treats different size for the same kind of character, also if it is because of their own implementation, then give me a way to convert the c++ unicode strings to java readable unicode strings.

Eg:
Expand|Select|Wrap|Line Numbers
  1. std::string cpluscplustoJava(std::string str)
  2. {
  3. /** 
  4.  * This function should return the same 
  5.  * string with length as 10 byes..:P, It is possible??
  6.  */
  7. }
  8.  
Aug 23 '13 #1
4 2562
Actually my string contains only 5 characters which is of square shape (unicode character), the bytes.com viewer shows like 10 characters as '?'. Don't get confused by it.
Aug 23 '13 #2
weaknessforcats
9,208 Expert Mod 8TB
You can't use string for Unicode. Unicode characters are 16 bits (2 bytes).

Instead of char you use wchar_t and instead of string and cout you use wstring and wcout. the w is for "wide character".

Only if the 16 bit pattern in the wchar_t matches a valid Unicode character do you have a Unicode character. Be advised that mapping (called encoding) varies in Unicode so some characters are 8 while others are 16.

With Windows you convert using WideCharToMultiByte().

You usually need to call OS functions to create Unicode strings.

Thus is a bigger topic than can be addressed in a thread like this.
Aug 23 '13 #3
@weeknessforcats Thanks for your reply, can you give me a link to understand the unicode much better in C++.
Aug 23 '13 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Borko | last post by:
hi I am having problems getting unicode characters into VB. Using VB6 (sp3) and Access 2000 Characters are displayed correctly in Access, just when I use ADODB (2.7) to read them in VB i get ?...
3
by: Kidus Yared | last post by:
I am having a problem displaying Unicode characters on my Forms labels and buttons. After coding Button1.Text = unicode; where the unicode is a Unicode character or string (‘\u1234’ or...
3
by: Mohammad-Reza | last post by:
We are writing an application for a specific culture(Arabic or Farsi). This application involves using DataAdapter, OLEDB Connection and the DataSet. We didn't use the .NET data binding, just field...
3
by: john | last post by:
I need to produce a RTF-document which is filled with data from a database. I've created a RTF-document in WordPad (a template, so to speak) which contains 'placeholders', for example '<dd01>',...
5
by: Matthew Thompson | last post by:
I have as issue I am finding hard to research. I use a stored proecdure in SQL 2000 to provide search capability for our database of news stories and articles. Being an international magazine...
10
by: Roger Withnell | last post by:
I'm using ASP, VBScript and SQL Server. I'm also using UTF-8 character set and so my codepage is 65001 and SQL Server datatype nvarchar. I can insert unicode characters correctly into the...
13
by: Kelvin Moss | last post by:
Hi all, How could one write an strstr function to work with unicode characters? Are there existing implementations/solutions/api for doing so? Any pointers would be appreciated. Thanks ..
6
by: geegeegeegee | last post by:
Hi All, I have come across a difficult problem to do with extracting UniCode characters from RTF strings. A detailed description of my problem is below, if anyone could help, it would be much...
0
by: M.-A. Lemburg | last post by:
On 2008-07-01 20:31, Peter Bulychev wrote: You could write a codec which translates Unicode into a ASCII lookalike characters, but AFAIK there is no standard for doing this. I guess the best...
2
borisding
by: borisding | last post by:
Hi there, I'm using Jmail for sending email with some attachments. Basically, I will need to send out email with the contents in unicode characters such as Simplified Chinese, Japanese etc. I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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,...

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.