字符串和字符数组之间的转换.docxVIP

  • 7
  • 0
  • 约7.14千字
  • 约 8页
  • 2017-01-26 发布于北京
  • 举报
字符串和字符数组之间的转换

字符串和字符数组之间的转换?2010-11-02 16:53:00|??分类:?C# .net 工具|举报|字号?订阅?字符串类?System.String?提供了一个?void ToCharArray()?方法,该方法可以实现字符串到字符数组的转换。如下例:?private?void?TestStringChars()?{???string?str =?mytest;???char[] chars = str.ToCharArray();???this.textBox1.Text =?;???this.textBox1.AppendText(Length of \mytest\ is ?+ str.Length +?\n);???this.textBox1.AppendText(Length of char array is ?+ chars.Length +?\n);???this.textBox1.AppendText(char[2] = ?+ chars[2] +?\n);???}? 例中以对转换转换到的字符数组长度和它的一个元素进行了测试,结果如下: Length of mytest is 6Length of char array is 6char[2] = t 可以看出,结果完全正确,这说明转换成功。那么反过来,要把字符数组转换成字符串又该如何呢?我们可以使用?Sys

文档评论(0)

1亿VIP精品文档

相关文档