•
•
•
•
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
![]() |
•
•
Join Date: Nov 2006
Posts: 13
Reputation:
Rep Power: 2
Solved Threads: 0
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 :/
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 :/
•
•
Join Date: Nov 2006
Location: The Deep South
Posts: 26
Reputation:
Rep Power: 2
Solved Threads: 1
How about this (if your strings are relatively short):
To get a count of each vowel without 'walking the string':
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
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
•
•
•
•
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!
Join today don't delay!
•
•
Join Date: Nov 2006
Location: The Deep South
Posts: 26
Reputation:
Rep Power: 2
Solved Threads: 1
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.
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.
•
•
•
•
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!
Join today don't delay!
•
•
Join Date: Nov 2006
Location: The Deep South
Posts: 26
Reputation:
Rep Power: 2
Solved Threads: 1
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
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
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.
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!
Join today don't delay!
![]() |
•
•
•
•
•
•
•
•
DaniWeb VB.NET Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Installing Windows 98 On VMware. Floppy problem (Windows 9x / Me)
- Windows XP keeps restarting since a new video card (Windows NT / 2000 / XP / 2003)
- Redhat Linux 6.2 - ipop3d problem? (*nix Software)
- Problem with T720 (Gadgets and Gizmos)
- Connection Problems (Networking Hardware Configuration)
- Encoding (Unicode) problem in IE 6.0 (Web Browsers)
- .htaccess mod_rewrite problem (Linux Servers and Apache)
- Javascript/HTML problem!!! (JavaScript / DHTML / AJAX)
- Problem with Windows Update and WinXP (Web Browsers)
Other Threads in the VB.NET Forum
- Previous Thread: [Moving from Listbox to an another]
- Next Thread: How to validate textbox with date type!!



Linear Mode