ascii - Java StringBuilder Appending Vertical-Tab Character Fails -
i receive data inputstream , have ascii character 11 vertical tab. can see vertical tab 11 in debugger. try append character stringbuilder appended , length increased.
however, problem when string returned ascii character lost when doing stringbuilder.tostring().tochararray() ascii character 11 can seen.
i need see in string ascii character 11.
public static void main(string[] args) { // receive data inputstream int read = inputstream.read(); stringbuilder stringbuilder = new stringbuilder(); stringbuilder.append((char) read); // /u000b ' ' stringbuilder.append("h"); system.out.println(stringbuilder.tostring()); // prints h char[] characters = stringbuilder.tostring().tochararray(); // length 2 }
how can achived?
edit:
i need see ascii character in original string in debugger. example:
public string getoriginalstring() { return originalstring; } public string process(string originalstring) { return modifiedstring; }
edit:
public string buildmessage(inputstream inputstream) throws exception { stringbuilder message = null; if(inputstream != null) { message = new stringbuilder(); bufferedinputstream bufferedinputstream = new bufferedinputstream(inputstream); int byteread = bufferedinputstream.read(); while(byteread != -1) { char value = (char) byteread; message.append(value); // check how many bytes available if(bufferedinputstream.available() != 0) { byteread = bufferedinputstream.read(); } else { // avoid blocking of data break; } } } char[] characters = message.tostring().tochararray(); // returns length 2 return message.tostring(); } public static void main(string[] args) { string = buildmessage(inputstream); char[] characters = i.tochararray(); // ascii characters lost stringbuilder stringbuilder = new stringbuider(i); char[] characters2 = stringbuilder.tostring().tochararray(); // ascii characters lost }
a vertical tab white-space, can not "see it". expect visual appear of vertical tab be? vertical tab ascii character a historical artefact, dating days teletypes. has has no accepted special meaning vdus , windoing systems displaying text.
Comments
Post a Comment