I am an experienced C++ programmer but new to Java.
I have an algorithm that does some string manipulation and I want to terminate a string in the middle.
Say, I want to do something like this
String str("hello, world");
char[] str2 = str.toCharArray();
//pass str2 to some function
myFunc(str2);
...
//inside myFunc, I decide to terminate str2 at position 3, so I did
//str2[3] = 0
//then it returns, how can I construct an String type variable from str2 that includes chars before the '\0'?
//String str3 = new String(str2), doesn't work
I can write my own C-liked strlen. However I would like to know what is the elegant way of doing it in Java.
Also, it is hard to find document about type char[]. Whenever I Google, I can only find document on "char" instead of "char[]". I am thinking char[] may have methods liked substr or strlen.
Thanks for any suggestion!
char.