Domanda

I am interested in the following ASCII characters 11 Vertical Tab, 28 File Separtor and 13 Carriage Return. Through Java, the Character.isWhitespace() will tell me whether these characters are one of these types.

What I want to do is send input data as a String. For example character 13 is '\r' so this can be inputted into a String:

String input = new String("'\'rThis is");

From this I can identify that character 0, 1 and 2 from input.toCharArray() is ASCII character 13. How can the Vertical Tab and File Separtor be represented in a String.

I have done a lot of research but Google does not give the answer. The Horizantal tab is the tab character such as " This is" but what is the Veritical tab?

È stato utile?

Soluzione

In principle, you can input them as Unicode codepoints, like so :

  • vertical tab : \u000b
  • file separator : \001c

I don't have my Java compiler at hand right now so I can't test if it actually works.

Altri suggerimenti

You can always get the char value for any ASCII character in java by doing (char) [asciiValue] in this case (char) 11 to get vertical tab.

File Separator is available using File.seperator, I believe.

You can construct a string from a byte array specifying each character.

String input = new String(new byte[] {11, 28, 13 });

Based on the following test, it appears that they are indeed all whitespace.

import java.util.*;
public class Foo {
    public static void main(String[] args) {            
        String input = new String(new byte[] {11, 28, 13 });
        System.out.println(Character.isWhitespace(input.charAt(0)));
        System.out.println(Character.isWhitespace(input.charAt(1)));
        System.out.println(Character.isWhitespace(input.charAt(2)));
    }
}

Output:

true
true
true
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top