将char []的一部分复制到String中 [英] copy only portion of char[] into String
本文介绍了将char []的一部分复制到String中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个数组char [] ch。我的问题如下。如何将ch [2]和ch [7]中的值合并为一个字符串?我想在不循环char数组的情况下实现这一点。有什么建议吗?
I have an array char[] ch. My question is the following. How can I merge values from ch[2] to ch[7] into a String? I would like to achieve this without looping through the char array. Any suggestions?
感谢您抽出宝贵时间回答我的问题。
Thanks for taking the time to answer my question.
推荐答案
使用 new String(value,offset,count)
, reference 。
其中offset是起始索引,count是您的索引差异。在你的情况下,它是7-2 = 5。
Where offset is the starting index and count is your index difference. In your case, it's 7-2=5.
显然,value是你的角色数组。
Obviously, value is your character array.
这篇关于将char []的一部分复制到String中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文