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,
05-11-2013, 03:27 AM #11
Pichu
RIP PICHU.
Originally posted by Princess
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


Works the exact same way. :P We have our likes and dislikes. I can tell you like for loops, I like foreach loops and while loops.
05-11-2013, 03:45 AM #12
Master Ro
I make food
Originally posted by Pichu View Post
Works the exact same way. :P We have our likes and dislikes. I can tell you like for loops, I like foreach loops and while loops.


Yea haha, I like for loops :p


By the way, are you getting on skype soon? I have a few things I would like to discuss with you Smile

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo