ControlChar class

ControlChar class

Control characters often encountered in documents. To learn more, visit the Working With Control Characters documentation article.


Provides both char and string versions of the same constants. For example: string ControlChar.LINE_BREAK and char ControlChar.LINE_BREAK_CHAR have the same value.


CELLEnd of a table cell or end of a table row character: “\x0007” or “\a”.
CELL_CHAREnd of a table cell or end of a table row character: (char)7 or “\a”.
COLUMN_BREAKEnd of column character: “\x000e”.
COLUMN_BREAK_CHAREnd of column character: (char)14.
CRCarriage return character: “\x000d” or “\r”. Same as ControlChar.PARAGRAPH_BREAK.
CR_LFCarriage return followed by line feed character: “\x000d\x000a” or “\r\n”. Not used as such in Microsoft Word documents, but commonly used in text files for paragraph breaks.
DEFAULT_TEXT_INPUT_CHARThis is the “o” character used as a default value in text input form fields.
FIELD_END_CHAREnd of MS Word field character: (char)21.
FIELD_SEPARATOR_CHARField separator character separates field code from field value. Optional in some fields. Value: (char)20.
FIELD_START_CHARStart of MS Word field character: (char)19.
LFLine feed character: “\x000a” or “\n”. Same as ControlChar.LINE_FEED.
LINE_BREAKLine break character: “\x000b” or “\v”.
LINE_BREAK_CHARLine break character: (char)11 or “\v”.
LINE_FEEDLine feed character: “\x000a” or “\n”. Same as ControlChar.LF.
LINE_FEED_CHARLine feed character: (char)10 or “\n”.
NON_BREAKING_HYPHEN_CHARNon-breaking Hyphen in Microsoft Word is (char)30.
NON_BREAKING_SPACENon-breaking space character: “\x00a0”.
NON_BREAKING_SPACE_CHARNon-breaking space character: (char)160.
OPTIONAL_HYPHEN_CHAROptional Hyphen in Microsoft Word is (char)31.
PAGE_BREAKPage break character: “\x000c” or “\f”. Note it has the same value as ControlChar.SECTION_BREAK.
PAGE_BREAK_CHARPage break character: (char)12 or “\f”.
PARAGRAPH_BREAKEnd of paragraph character: “\x000d” or “\r”. Same as ControlChar.CR
PARAGRAPH_BREAK_CHAREnd of paragraph character: (char)13 or “\r”.
SECTION_BREAKEnd of section character: “\x000c” or “\f”. Note it has the same value as ControlChar.PAGE_BREAK.
SECTION_BREAK_CHAREnd of section character: (char)12 or “\f”.
SPACE_CHARSpace character: (char)32.
TABTab character: “\x0009” or “\t”.
TAB_CHARTab character: (char)9 or “\t”.


Shows how to use control characters.

doc = aw.Document()
builder = aw.DocumentBuilder(doc)

# Insert paragraphs with text with DocumentBuilder.
builder.writeln("Hello world!")
builder.writeln("Hello again!")

# Converting the document to text form reveals that control characters
# represent some of the document's structural elements, such as page breaks.
self.assertEqual("Hello world!" + aw.ControlChar.CR +
                 "Hello again!" + aw.ControlChar.CR +
                 aw.ControlChar.PAGE_BREAK, doc.get_text())

# When converting a document to string form,
# we can omit some of the control characters with the "strip" method.
self.assertEqual("Hello world!" + aw.ControlChar.CR +
                 "Hello again!", doc.get_text().strip())

See Also