User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the VB.NET section within the Software Development category of DaniWeb, a massive community of 401,951 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,344 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Views: 4691 | Replies: 26
Reply
Join Date: Nov 2006
Posts: 13
Reputation: vb_learner is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
vb_learner vb_learner is offline Offline
Newbie Poster

Help hello i have a problem

  #1  
Nov 1st, 2006
Hello : >
I'm using console application (VB.NET), using Visual Studio 2005.

I have a problem with my project, I'm building a vowel counter program, and faced a problem there with loops..
any one can help me with my project?,,
can I contact with the helper using a private message?

thanks alot in advance ..
I really need a help :/
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2006
Posts: 6
Reputation: Yankie Dave is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Yankie Dave Yankie Dave is offline Offline
Newbie Poster

Re: hello i have a problem

  #2  
Nov 1st, 2006
I don't use messenger programs, but if you post the code you have we can take a look and see where your problem lies.
Reply With Quote  
Join Date: Aug 2005
Posts: 4,711
Reputation: iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light 
Rep Power: 17
Solved Threads: 309
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Industrious Poster

Re: hello i have a problem

  #3  
Nov 1st, 2006
It's pretty simple:

You have a string, you loop through each character of the string and increment the counter every time it encounters a vowel.
Member of: F-ugly code club

Join today don't delay!
Reply With Quote  
Join Date: Nov 2006
Posts: 13
Reputation: vb_learner is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
vb_learner vb_learner is offline Offline
Newbie Poster

Re: hello i have a problem

  #4  
Nov 1st, 2006
thank you both for your answering my question : )
i'll come back and continue my question : )
Reply With Quote  
Join Date: Nov 2006
Location: The Deep South
Posts: 26
Reputation: NedFrankly is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
NedFrankly NedFrankly is offline Offline
Light Poster

Solution Re: hello i have a problem

  #5  
Nov 3rd, 2006
How about this (if your strings are relatively short):

To get a count of each vowel without 'walking the string':

' strMyText is the string returned from the console
 
dim strMyTextCaps = strMyText.toUpper()  'We don't care about case
dim intTextLen = strMyText.length ' So we don't reevaluate every time
 
dim intCountA = intTextLen - (strMyTextCaps.Replace("A","").length)
dim intCountE = intTextLen - (strMyTextCaps.Replace("E","").length)
' etc...

It should be fairly obvious, but what we're doing is getting the length of the original string, and then replacing each vowel with an empty string. We subtract the new length from the original length and know the number of characters replaced. This is the vowel count for that vowel.

Haven't benchmarked for performance (nor have I run this - I believe the syntax is correct). A single line for each vowel is easier to read than a bunch of loops. Performance should not be a problem anyway, if the text is provided via the console.

Happy Coding!

Ned
Last edited by NedFrankly : Nov 3rd, 2006 at 2:14 pm. Reason: Clarification
Reply With Quote  
Join Date: Aug 2005
Posts: 4,711
Reputation: iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light 
Rep Power: 17
Solved Threads: 309
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Industrious Poster

Re: hello i have a problem

  #6  
Nov 3rd, 2006
Originally Posted by NedFrankly View Post
How about this (if your strings are relatively short):

To get a count of each vowel without 'walking the string':

' strMyText is the string returned from the console
 
dim strMyTextCaps = strMyText.toUpper()  'We don't care about case
dim intTextLen = strMyText.length ' So we don't reevaluate every time
 
dim intCountA = intTextLen - (strMyTextCaps.Replace("A","").length)
dim intCountE = intTextLen - (strMyTextCaps.Replace("E","").length)
' etc...

It should be fairly obvious, but what we're doing is getting the length of the original string, and then replacing each vowel with an empty string. We subtract the new length from the original length and know the number of characters replaced. This is the vowel count for that vowel.

Haven't benchmarked for performance (nor have I run this - I believe the syntax is correct). A single line for each vowel is easier to read than a bunch of loops. Performance should not be a problem anyway, if the text is provided via the console.

Happy Coding!

Ned


If you're replacing every vowel with the same "", how would you tell the difference between each vowel?

Wait unless you're reading the string five times in, i.e the number of vowels there are aeiou?
Last edited by iamthwee : Nov 3rd, 2006 at 2:19 pm.
Member of: F-ugly code club

Join today don't delay!
Reply With Quote  
Join Date: Nov 2006
Location: The Deep South
Posts: 26
Reputation: NedFrankly is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
NedFrankly NedFrankly is offline Offline
Light Poster

Re: hello i have a problem

  #7  
Nov 3rd, 2006
We don't care about the number of "",s we care about the difference between the old length (with the vowels intact) and the new length (with one of the vowels converted to ""). Example:

Text = "I am here"
Length of original Text = 9
Text after Replace("a","") = "I m here"
Length of new Text = 8
Difference = 1, therefore Count of A's in the text = 1.

We can ignore leading and trailing blanks because we are not counting any characters - we're replacing all occurances of one character with a no-space and getting the difference in lengths.
Reply With Quote  
Join Date: Aug 2005
Posts: 4,711
Reputation: iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light 
Rep Power: 17
Solved Threads: 309
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Industrious Poster

Re: hello i have a problem

  #8  
Nov 3rd, 2006
Originally Posted by NedFrankly View Post
We don't care about the number of "",s we care about the difference between the old length (with the vowels intact) and the new length (with one of the vowels converted to ""). Example:

Text = "I am here"
Length of original Text = 9
Text after Replace("a","") = "I m here"
Length of new Text = 8
Difference = 1, therefore Count of A's in the text = 1.

We can ignore leading and trailing blanks because we are not counting any characters - we're replacing all occurances of one character with a no-space and getting the difference in lengths.


Yes I just realised that and have since edited my post, however, your program requires you to read the string in five times.
Member of: F-ugly code club

Join today don't delay!
Reply With Quote  
Join Date: Nov 2006
Location: The Deep South
Posts: 26
Reputation: NedFrankly is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
NedFrankly NedFrankly is offline Offline
Light Poster

Re: hello i have a problem

  #9  
Nov 3rd, 2006
Indeed, it does. Here's where hard-won philosophy of programming comes in (I don't know your experience, but I've been at this most of my life). The most efficient answer is not always the best. In this case, it's preferable that the code be clear and concise (once the programmer understands the concept, and I got the impression that the original question may have been asked by a fairly new programmer). The trade-off is between having to walk the string character by character and compare each one (costly in and of itself) or have the system return the same results without iterating.

You'll find if you read anything I've posted here or on the web that I really get into 'different' algorythms to solve standard problems. I typically know the direction most programmers take given a standard problem like this one (because that's the first direction that comes to my mind as well), so I take that information and try to find a more elegant solution. It's a hobby of mine, and my 'weird' solutions have at time improved program performance by 10 or 100 fold. It's a good hobby, but I do admit that sometimes my elegant solution is not scalable, or is nice in theory but doesn't cut it in the real world. That's ok, if it gets me (and other programmers) to think in different ways then we've all learned something.

Thanks!

Ned
Reply With Quote  
Join Date: Aug 2005
Posts: 4,711
Reputation: iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light 
Rep Power: 17
Solved Threads: 309
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Industrious Poster

Re: hello i have a problem

  #10  
Nov 3rd, 2006
I agree with that! It's a nice simple solution and would be tolerable if the string is short, like you have originally said.

I've only just really begun GUI coding, I mainly focus on code that is written. I enjoy using OOP and all it's advantages (inheritance etc) I am also a fan of data structures, i.e using stacks binaray trees and queues.

Like you I have an affinity for all languages, and I also enjoy working with 3d models graphics and rendering.
Member of: F-ugly code club

Join today don't delay!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb VB.NET Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the VB.NET Forum

All times are GMT -4. The time now is 5:34 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC