Post: [SOURCE] Vowel Finder [C#]
03-06-2013, 06:02 AM #1
Master Ro
I make food
(adsbygoogle = window.adsbygoogle || []).push({}); Hey guys, I was just going to put out the source for a little program I made. This program finds all the vowels in a text string and prints them in a text box. It's a simple program just to better my understanding of C#. Credits to Jakes625Ps3 for showing me the method that finds a sub string.

Images:

You must login or register to view this content.

You must login or register to view this content.


Source:


    
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Vowel_Counter
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
try
{
GetVowel(textBox1.Text);
}
catch
{
MessageBox.Show("Please Enter a string!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

private void GetVowel(string voweltext)
{
//Arrange the text into a character array
char[] Arr = voweltext.ToCharArray();
//Start our vowel count
int VowelCount = 0;
//Reset out text strings
textBox2.Text = null;
label2.Text = "Vowels:";

for (int i = 0; i < Arr.Length; i++)
{
switch (Arr[i].ToString().ToLower())
{
case "a":
case "e":
case "i":
case "o":
case "u":
//Input the vowel in textbox2
textBox2.Text += Arr[i].ToString() + "; ";
//Increase the vowel count by one
VowelCount++;
break;
}
}

//Remove the last character of our string
string NewText = textBox2.Text.Substring(0, textBox2.Text.Length - 2);
//Set the new text
textBox2.Text = NewText;
//Update label text to include the number of vowels.
label2.Text += ' ' + VowelCount.ToString();
}
}
}


The whole Visual Studio file isn't included, so one can't compile and run this source code. It just gives one an idea on how to do it.

The following 2 users say thank you to Master Ro for this useful post:

Pichu,
03-07-2013, 02:50 AM #2
Pichu
RIP PICHU.
Good job, however I would have handled it differently. Smile

None-the-less good job. Smile
03-08-2013, 06:12 PM #3
Sonoro
I like anteaters
Nice Fagger Ro!

As Pichu said, it can be handled in a different way, but still something made just to learn, there isn't a real reason to use it for something :mmm:

The following user thanked Sonoro for this useful post:

Pichu
03-09-2013, 04:57 AM #4
Pichu
RIP PICHU.
Originally posted by xSonoro View Post
Nice Fagger Ro!

As Pichu said, it can be handled in a different way, but still something made just to learn, there isn't a real reason to use it for something :mmm:


Some of the ways that I program, I use every method possible that makes it complex but logical. Doing very complex things while thinking of how to do it and implementing that in order to do something that you know you could have done in fewer lines helps with memorization and helps with developing better logical skills.

Happy
04-01-2013, 08:15 PM #5
*xActionMods*
I’m too L33T
Originally posted by Uncle
Hey guys, I was just going to put out the source for a little program I made. This program finds all the vowels in a text string and prints them in a text box. It's a simple program just to better my understanding of C#. Credits to Jakes625Ps3 for showing me the method that finds a sub string.

Images:

You must login or register to view this content.

You must login or register to view this content.


Source:


    
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Vowel_Counter
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
try
{
GetVowel(textBox1.Text);
}
catch
{
MessageBox.Show("Please Enter a string!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

private void GetVowel(string voweltext)
{
//Arrange the text into a character array
char[] Arr = voweltext.ToCharArray();
//Start our vowel count
int VowelCount = 0;
//Reset out text strings
textBox2.Text = null;
label2.Text = "Vowels:";

for (int i = 0; i < Arr.Length; i++)
{
switch (Arr[i].ToString().ToLower())
{
case "a":
case "e":
case "i":
case "o":
case "u":
//Input the vowel in textbox2
textBox2.Text += Arr[i].ToString() + "; ";
//Increase the vowel count by one
VowelCount++;
break;
}
}

//Remove the last character of our string
string NewText = textBox2.Text.Substring(0, textBox2.Text.Length - 2);
//Set the new text
textBox2.Text = NewText;
//Update label text to include the number of vowels.
label2.Text += ' ' + VowelCount.ToString();
}
}
}


The whole Visual Studio file isn't included, so one can't compile and run this source code. It just gives one an idea on how to do it.


for the file to look like that, must it be coded from a windows 8 computer?
05-10-2013, 07:43 PM #6
TheHolyMart
I am error
Originally posted by 9830
for the file to look like that, must it be coded from a windows 8 computer?


No, only executed from windows 8.
05-10-2013, 07:57 PM #7
Pichu
RIP PICHU.
Originally posted by TheHolyMart View Post
No, only executed from windows 8.


Originally posted by 9830
for the file to look like that, must it be coded from a windows 8 computer?


You two made me laugh. :P

It can be coded on anything that has the run-time environment. The computer doesn't have to be Windows 8 to look like that. Could be XP with a heavily modified theme. Could be a custom theme put onto the application. :P

:mmm::mmm::mmm:
05-10-2013, 09:26 PM #8
TheHolyMart
I am error
Originally posted by Pichu View Post
You two made me laugh. :P

It can be coded on anything that has the run-time environment. The computer doesn't have to be Windows 8 to look like that. Could be XP with a heavily modified theme. Could be a custom theme put onto the application. :P


At first i didnt want to answer. Thats exactly why LOL. thank you BTW Smile
05-11-2013, 01:38 AM #9
Pichu
RIP PICHU.
Originally posted by Princess
Hey guys, I was just going to put out the source for a little program I made. This program finds all the vowels in a text string and prints them in a text box. It's a simple program just to better my understanding of C#. Credits to Jakes625Ps3 for showing me the method that finds a sub string.

Images:

You must login or register to view this content.

You must login or register to view this content.


Source:


    
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Vowel_Counter
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
try
{
GetVowel(textBox1.Text);
}
catch
{
MessageBox.Show("Please Enter a string!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

private void GetVowel(string voweltext)
{
//Arrange the text into a character array
char[] Arr = voweltext.ToCharArray();
//Start our vowel count
int VowelCount = 0;
//Reset out text strings
textBox2.Text = null;
label2.Text = "Vowels:";

for (int i = 0; i < Arr.Length; i++)
{
switch (Arr[i].ToString().ToLower())
{
case "a":
case "e":
case "i":
case "o":
case "u":
//Input the vowel in textbox2
textBox2.Text += Arr[i].ToString() + "; ";
//Increase the vowel count by one
VowelCount++;
break;
}
}

//Remove the last character of our string
string NewText = textBox2.Text.Substring(0, textBox2.Text.Length - 2);
//Set the new text
textBox2.Text = NewText;
//Update label text to include the number of vowels.
label2.Text += ' ' + VowelCount.ToString();
}
}
}


The whole Visual Studio file isn't included, so one can't compile and run this source code. It just gives one an idea on how to do it.



FYI: Just did this in less than 5 minutes. Does exactly what your code does.

You must login or register to view this content.

No reason to turn the input into a list array, but I prefer it as it allows for doing a lot more than keeping it a string.
Last edited by Pichu ; 05-11-2013 at 01:42 AM.
05-11-2013, 01:56 AM #10
Master Ro
I make food
Originally posted by Pichu View Post
FYI: Just did this in less than 5 minutes. Does exactly what your code does.

You must login or register to view this content.

No reason to turn the input into a list array, but I prefer it as it allows for doing a lot more than keeping it a string.


Haha, I made this a while ago. I re-did it now, and this is what I came up with.

Code: You must login or register to view this content.
Image: You must login or register to view this content.

:p

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo