Click here to Skip to main content
15,883,916 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I want to write a program that calculates the number of words in a particular word in a particular text string
Posted
Comments
AnkitGoel.com 10-Dec-12 0:08am    
do you want to calculate number or occurances of a word in a string?

Count words include space
dim count_ as double = textbox1.text.lenght 

Or

dim count_ as double = len(textbox1.text)
 
Share this answer
 
Not sure what you mean by, "the number of words in a particular word".

If you mean you want to count words in a string then here's a starting point for you (check the exact syntax). It assumes a single space between each word.

VB
dim words as string() = sentence.split(" ")
dim wordCount as integer = words.length


Look at the string.replace() method for a simple way of removing multiple spaces from the input. Then look at regex for a more sophisticated way of removing multiple occurrences of characters/strings.

If that isn't what you mean by your question please give an example of what you're trying to do.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900