Friday, November 19, 2010

VBScriptCode - Counting the number of words, spaces and characters (excluding spaces) in a string

Write the below code in a notepad and save it as a .vbs file. Either run it from command prompt or run it by double-clicking on it.


VBScript Code - Counting the number of words, spaces and characters (excluding spaces) in a string

x=inputbox("Enter a string: ")
words_str = Split(x)

msgbox "No. of words are " & ubound (words_str) +1
msgbox "No. of spaces are " & ubound (words_str)

for each k in words_str
  char_len = char_len + len(k)
next

msgbox "No. of characters excluding spaces are " & char_len