Monday, 8 August 2011

Count Number Of words in String/Document

str = "my name is pankaj"
words= Split(str," ")
MsgBoxUBound(words)+1
'In case If you have to count the number of word in Notepad then you can use the following approch .

Set np = CreateObject("scripting.filesystemobject")
Set onp = np.OpenTextFile("C:\Documents and Settings\sharmapa\Desktop\Blog.txt",1)
str = onp.ReadAll
words= Split(str," ")
MsgBoxUBound(words)+1

No comments:

Post a Comment