So, I currently have a char array of 2000 chars. I will have 24 or less chars in the middle of this array that I need turned into a string. I have no ideas how to do this after many logic combinations and Google searches. Any help is appreciated!
-
2have you written any code yet on this or just trying to get idea.?Saif– Saif2015-02-04 05:11:19 +00:00Commented Feb 4, 2015 at 5:11
-
A lot of code and a lot of failures that I deleted. I can recreate some of what I deleted.Andrew Fey– Andrew Fey2015-02-04 05:14:14 +00:00Commented Feb 4, 2015 at 5:14
Add a comment
|
2 Answers
String provides a constructor designed specifically for this task:
char[] bigData = ...
int startIndex = ...
int len = ...
String res = new String(bigData, startIndex, length);
startIndex represents the position in the array of characters where your string should begin; len represents the number of characters to take.
Comments
try this constructor
String(char[] value, int offset, int count)
2 Comments
Andrew Fey
Can you explain what is meant o be plugged into the offset and count
Evgeniy Dorofeev
If char[] a = {'a','b','c','d'} then new String(a,1,2) will make "bc"