Click here to Skip to main content
12,759,096 members (33,250 online)
Rate this:
Please Sign up or sign in to vote.
See more: VB VB.NET
I want to write a program that calculates the number of words in a particular word in a particular text string
Posted 8-Dec-12 10:08am
Comments 10-Dec-12 0:08am
do you want to calculate number or occurances of a word in a string?
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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


dim count_ as double = len(textbox1.text)
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.

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.

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

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170217.1 | Last Updated 10 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100