![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
|
Hi,
I'm trying to count the number of letters in a string. e.g. I want to know how many e's there would be in string1 or t's there would be in string2 I was going to display them in a datagrid but abandoned that idea and now want to display them as individual integers so how many e's there are would be something like intE. Thanks! mattireland |
|
|
|
|
|
#2 |
|
Professional Programmer
|
Re: Counting Number of Letters in a String
Iterate through the string character by character and count the occurrences of each letter
![]()
__________________
http://www.kevinherron.com/ |
|
|
|
|
|
#3 |
|
Programming Guru
![]() ![]() ![]() |
Re: Counting Number of Letters in a String
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#4 |
|
Not a user?
Join Date: Sep 2007
Posts: 245
Rep Power: 1
![]() |
Re: Counting Number of Letters in a String
irrelevant reply and no way to delete post any longer.
|
|
|
|
|
|
#5 |
|
Expert Programmer
|
Re: Counting Number of Letters in a String
This is an easy way to do it in C#. I'm sure .NET has easier built in functions though. All you'll have to do is convert it over, but for the most part it's the same.
csharp Syntax (Toggle Plain Text)
|
|
|
|
|
|
#6 |
|
Hobbyist Programmer
|
Re: Counting Number of Letters in a String
Thanks very much guys! Especially to IR and Booze (IR I used that link and found loads of other good stuff on there - thanks! Booze thanks for that I used it in a C# variation that I was doing). I was waiting until I had the program finished before I replied to this thread so you could see what I've done with it but alas, I've not quite finished it yet.
Thanks again, Matt. |
|
|
|
|
|
#7 |
|
Newbie
Join Date: May 2008
Posts: 1
Rep Power: 0
![]() |
just out of interest what is the purpose of this program?
Last edited by knetcozd; May 23rd, 2008 at 6:10 AM. |
|
|
|
|
|
#8 |
|
Programmer
Join Date: Nov 2007
Posts: 86
Rep Power: 1
![]() |
Re: Counting Number of Letters in a String
of course .net has easier built in functions:
c# Syntax (Toggle Plain Text)
|
|
|
|
|
|
#9 |
|
Hobbyist Programmer
|
Re: Counting Number of Letters in a String
Thanks.
@ knetcozd: Cipher cracking. |
|
|
|
|
|
#10 |
|
Battle Programmer
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 746
Rep Power: 3
![]() |
Re: Counting Number of Letters in a String
Assuming you're doing this by frequency analysis, you should probably opt for a method where you have an array of 26 ints (one per letter), or something along the lines of Dictionary(Of Char, Integer) so you can get the counts for all of the letters with a single pass.
__________________
<insert disclaimer here> <insert shameless plug for Visual Studio here> |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| An Attempt at a DBMS | grimpirate | PHP | 8 | Apr 17th, 2007 1:01 PM |
| Throwing an exception when using string constructor | csrocker101 | C# | 3 | Apr 8th, 2007 2:04 PM |
| Counting a single character in a string | tbohon | Perl | 3 | Jul 13th, 2006 9:23 AM |
| finding the number of spaces in a String | squishiful | Java | 6 | Jul 6th, 2005 5:43 PM |
| Counting Number of Leaf Nodes Recursively(Binary Search Tree) | BaroN NighT | C++ | 7 | Apr 26th, 2005 9:28 PM |