如何将字符串的内容复制到char数组? [英] How do I copy the content of a string to a char array?

查看:89
本文介绍了如何将字符串的内容复制到char数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将一个编码(在我的情况下为big5)中的字符串内容复制到具有相同编码的

字符数组?


我尝试以下


String line [] = S" 123?°'?3¥" ;;

char buffer [200];


for(int i = 0; i< line-> get_length(); i ++)

{

buffer [i] = (char)line-> Chars [i];

}


它适用于前3个Ascii字符,但是搞砸了

接下来2个汉字。这里有什么问题?

How do I copy the content of a string in one encoding (in my case big5) to a
char array of the same encoding?

I try the following

String line[] = S"123?°′?3¥";
char buffer[200];

for(int i=0; i<line->get_length(); i++)
{
buffer[i] = (char) line->Chars[i];
}

It works fine for the first 3 Ascii characters, but gets messed up for the
next 2 Chinese characters. What is wrong here?

推荐答案

Kueishiong Tu写道:
Kueishiong Tu wrote:
如何在一个编码中复制字符串的内容(在我的情况下,big5)到一个相同编码的字符数组?

我尝试以下

字符串行[] = S" 123?°' ?3¥" ;;
char buffer [200];

for(int i = 0; i< line-> get_length(); i ++)
{
buffer [i] =(char)line-> Chars [i];
}
它适用于前3个Ascii字符,但是对于
接下来2个汉字。这里有什么问题?
How do I copy the content of a string in one encoding (in my case big5) to a
char array of the same encoding?

I try the following

String line[] = S"123?°′?3¥";
char buffer[200];

for(int i=0; i<line->get_length(); i++)
{
buffer[i] = (char) line->Chars[i];
}

It works fine for the first 3 Ascii characters, but gets messed up for the
next 2 Chinese characters. What is wrong here?



尝试使用WChar而不是Char。


Try to use WChar instead of Char.


为什么不使用像

char buffer [] = line.ToCharArray();


/ LM

" choongseng" < CH ******** @ gmail.com>在留言中写道

新闻:%2 *************** @ TK2MSFTNGP10.phx.gbl ...
why not use the ToCharArray method like in

char buffer[] = line.ToCharArray() ;

/LM
"choongseng" <ch********@gmail.com> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...
Kueishiong Tu写道:
Kueishiong Tu wrote:
如何将一个字符串的内容(在我的情况下为big5)复制到相同编码的char数组中?

我试试以下String line [] = S" 123 ??" ;;
char buffer [200];

for(int i = 0; i< line-> get_length(); i ++)
{
缓冲[i] =(char)line-> Chars [i];
}
它对前3个Ascii字符工作正常,但是对于接下来的2个汉字搞砸了。这有什么问题?
How do I copy the content of a string in one encoding (in my case big5)
to a char array of the same encoding?

I try the following String line[] = S"123??";
char buffer[200];

for(int i=0; i<line->get_length(); i++)
{
buffer[i] = (char) line->Chars[i];
}

It works fine for the first 3 Ascii characters, but gets messed up for
the next 2 Chinese characters. What is wrong here?


尝试使用WChar代替Char。


Try to use WChar instead of Char.



Kueishiong Tu< Ku ***** *****@discussions.microsoft.com>写道:
Kueishiong Tu <Ku**********@discussions.microsoft.com> wrote:
如何将一个编码(在我的情况下为big5)中的字符串内容复制到相同编码的
字符数组?

我尝试以下

String line [] = S" 123 ??" ;;
char buffer [200];

for(int i = 0; i< ; line-> get_length(); i ++)
{
buffer [i] =(char)line-> Chars [i];
}

它对前3个Ascii字符工作正常,但是对于接下来的2个汉字而搞砸了。这里有什么问题?
How do I copy the content of a string in one encoding (in my case big5) to a
char array of the same encoding?

I try the following

String line[] = S"123??";
char buffer[200];

for(int i=0; i<line->get_length(); i++)
{
buffer[i] = (char) line->Chars[i];
}

It works fine for the first 3 Ascii characters, but gets messed up for the
next 2 Chinese characters. What is wrong here?




字符数组不具有*单独的编码 - 字符

*总是* Unicode in .NET。


参见 http://www.pobox.com/~skeet/csharp/unicode.html 了解更多

信息。


-

Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet 博客: http://www.msmvps.com/jon.skeet

如果回复小组,请不要给我发邮件



Character arrays don''t *have* separate encodings as such - characters
are *always* Unicode in .NET.

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

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

这篇关于如何将字符串的内容复制到char数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆