This documentation is archived and is not being maintained.

How to: Count Characters in Documents

NoteNote

Some code examples in this topic use the this or Me keyword or the Globals class in a way that is specific to document-level customizations, or they rely on features of document-level customizations such as host controls. These examples can be compiled only if you have the required applications installed. For more information, see Features Available by Product Combination.

The first character in a document is at character position 0, which represents the insertion point. The last character position is equal to the total number of characters in the document. You can determine the number of characters in a document by using the Count property of the Characters collection.

All characters in the document are counted, including spaces, paragraph marks, and other characters that are normally hidden. Even a new, blank document returns a count of one character because it contains a paragraph mark.

To display the number of characters in a document

  1. Select the entire document.

    Word.Range rng = this.Content; 
    rng.Select(); 
    
    
  2. Display the number of characters in the document in a message box.

    MessageBox.Show("Characters: " + this.Characters.Count.ToString());
    
    

See Also

Show: