Unicode code point
Call Character.toString
while passing the Unicode code point of that character.
Understand that Unicode is a superset of US-ASCII. All the 128 characters in ASCII make up the first 128 of the 144,697 characters defined in Unicode, at code points 0-127.
For the group separator non-printable character, the decimal integer for its code point is 29.
\u001D
You can write that number 29
using its hexadecimal version 1D
as an escaped Unicode code point in a String
literal: \u001D
.
"dog\u001Dcat" // A string of seven characters.
Character.toString( 29 )
For frequent use, define a constant.
Calling Character.toString( 29 )
produces a String
containing a single character, your group separator.
final String FILE_SEPARATOR = Character.toString( 28 ) ;
final String GROUP_SEPARATOR = Character.toString( 29 ) ;
final String RECORD_SEPARATOR = Character.toString( 30 ) ;
final String UNIT_SEPARATOR = Character.toString( 31 ) ;
Or make a class with statics. Here for brevity we use the two-character abbreviated names defined in ASCII.
public class Ascii
{
static final String FS = Character.toString( 28 ) ;
static final String GS= Character.toString( 29 ) ;
static final String RS= Character.toString( 30 ) ;
static final String US= Character.toString( 31 ) ;
}
Usage:
myStringBuilder.append( Ascii.GS ) ;
For those not familiar with these separator characters, see the Question, What are the file/group/record/unit separator control characters and their usage?.
By the way, while researching this I discovered that Unicode also defines a character SYMBOL FOR GROUP SEPARATOR (code point 9,245) for documentation that needs to display something visibly that means the unprintable character.