Independentsoft
- any library, any programming language
Home
Purchase
Support
Company
Contact
Word .NET
>
Tutorial
> Word count
The example shows you how to open a document and count number of words.
C# example
using System; using Independentsoft.Office; using Independentsoft.Office.Word; namespace Sample { class Program { static void Main(string[] args) { WordDocument doc = new WordDocument("c:\\test\\input.docx"); string text = doc.ToText(); string[] separator = new string[] { " ", "\r\n", "\t" }; string[] words = text.Split(separator, StringSplitOptions.RemoveEmptyEntries); Console.WriteLine("Word count = " + words.Length); Console.Read(); } } }
VB example
Imports System Imports Independentsoft.Office Imports Independentsoft.Office.Word Module Module1 Sub Main(ByVal args As String()) Dim doc As New WordDocument("c:\test\input.docx") Dim text As String = doc.ToText() Dim separator As String() = New String() {" ", "" & Chr(13) & "" & Chr(10) & "", "" & Chr(9) & ""} Dim words As String() = text.Split(separator, StringSplitOptions.RemoveEmptyEntries) Console.WriteLine("Word count = " & words.Length) Console.Read() End Sub End Module
Need help? Ask our developers:
Name*
Email*
Message*