Posts: 3,538
Threads: 348
Joined: Mar 2010
Reputation:
57
(04-16-2011, 03:28 AM)Infinity Wrote: See I don't know pig latin though so i'd have to take the time to learn how it's derived from the english language first to be able to make the functions to translate it. In his example, all I seen was appending text to the original word really
For Preview Post though, it would be Eview-pray Ost-pay, which is more than just appending text, you're also rearranging the structure of the original words, putting "EView" before "Pr" for example.
The High Roller did a good job, although as Untouch said there's so much coding which is just not necessary.
Posts: 1,106
Threads: 195
Joined: Sep 2010
Reputation:
17
Hahaha... Arrays would take foreverish. But I am just saying that because I don't know how to use them. At least I tired, and the funny thing is that it works too.
Posts: 128
Threads: 10
Joined: Jan 2011
Reputation:
1
I think i can code this, but it would take alot of time. I have 2 weeks vacation, maybe i will start coding on it.
Posts: 341
Threads: 34
Joined: Nov 2010
Reputation:
8
(04-16-2011, 03:28 AM)Infinity Wrote: See I don't know pig latin though so i'd have to take the time to learn how it's derived from the english language first to be able to make the functions to translate it. In his example, all I seen was appending text to the original word really
Pig latin is not a real language. It's just a play on words. To form a word in pig latin you take a word such as:
Baseball...
you cut it off at the 'a' because it's the first vowel. Making it:
aseball...
then you put the letter back on to the end and add 'ay'. Making it:
aseball-bay.
Other ex:
Tennis -> ennis-tay
Soccer -> occer-say
Dinner -> inner-day
If the word starts with a vowel, you just put 'way' on the end.
Ex:
apple-way
english-way
arm-way
Hope that clears it up. Sorry, I thought everyone would have known what pig latin was that's why I chose this.
Posts: 1,677
Threads: 58
Joined: Jul 2010
Reputation:
30
(04-16-2011, 07:53 AM)The High Roller Wrote: Hahaha... Arrays would take foreverish. But I am just saying that because I don't know how to use them. At least I tired, and the funny thing is that it works too.
Haha I thought you said you were good at vb and you can't even do arrays! They're simple, look at tutorials because they are very effective and can be powerful if used correct.
Also it would be much quicker to use arrays.
@Kobe
I didn't know what pig latin was until your first post of the thread and thought it was pretty easy to understand. lol
Posts: 1,106
Threads: 195
Joined: Sep 2010
Reputation:
17
(04-16-2011, 11:25 AM)Untouch Wrote: Haha I thought you said you were good at vb and you can't even do arrays! They're simple, look at tutorials because they are very effective and can be powerful if used correct.
Also it would be much quicker to use arrays.
@Kobe
I didn't know what pig latin was until your first post of the thread and thought it was pretty easy to understand. lol
I am good at VB, I just never focused on arrays. Promise you that, you know when pros can do such hard things and cant do the easy? Yes thats me.
Posts: 341
Threads: 34
Joined: Nov 2010
Reputation:
8
04-16-2011, 12:35 PM
(This post was last modified: 04-17-2011, 04:30 PM by KoBE.)
Click here to download the Binary
Click here to download demo projects (C# and VB.Net)
VB.Net (fixed a bug to check whether the word has a vowel)
Code: Public Class Form1
'.Net Coding Challeng #1 by KoBE.
'Enjoy!
Private Sub btnEngtoPig_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEngtoPig.Click
'Checks to make sure text is entered
If txtConvert.Text = "" Then
MessageBox.Show("No text was entered")
Exit Sub
End If
'splits the entire sentence into words
Dim strWords() As String = txtConvert.Text.Split(" ")
For i = 0 To strWords.Length - 1
'this loops through each word converting it to pig-latin
strWords(i) = EngToPig(strWords(i))
Next
'after each word is converted, it joins the string together and seperates
'each word by a space
txtOutput.Text = Join(strWords, " ")
End Sub
Private Sub btnPigtoEng_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPigtoEng.Click
'if there are no hyphens, then we can't translate
If Not txtConvert.Text.Contains("-") Then
MessageBox.Show("This is not a valid Pig-Latin senence")
Exit Sub
End If
'sepearte each word into a string array
Dim strWords() As String = txtConvert.Text.Split(" ")
For i = 0 To strWords.Length - 1
'translate each word
strWords(i) = PigToEng(strWords(i))
Next
'join each translated word back to a sentence
txtOutput.Text = Join(strWords, " ")
End Sub
Private Function EngToPig(ByVal strWord As String) As String
Dim chrVowel As Char 'used to find our first vowel
Dim strSplit As String 'used to take the first part of the word and append at the end
Dim strResult As String 'holds our finished value
Dim iIndex As Integer 'helps split the text at the vowel
For i = 0 To strWord.Length - 1
'this loops through each character to find the first vowel
chrVowel = strWord.Substring(i, 1)
Select Case chrVowel.ToString.ToLower
Case "a", "e", "i", "o", "u", "y"
'if it's the first character only append -way to the end
If i = 0 Then Return strWord & "-way"
'strSplit becomes what we attach to the end
strSplit = strWord.Substring(0, i).ToLower
'this is going to be the position of the first vowel
iIndex = strWord.IndexOf(chrVowel)
'we want our new word to start at the vowel, then have everthing else added to the end with 'ay'
strResult = strWord.Substring(iIndex, strWord.Length - iIndex) & "-" & strSplit & "ay"
'return the translated word
Return strResult
Exit For
End Select
Next
MessageBox.Show("There are no vowels. Therefore a conversion cannot be done")
Return ""
End Function
Private Function PigToEng(ByVal strWord As String) As String
Dim iIndex As Integer = strWord.IndexOf("-") 'used to find our split
Dim iLastIndex As Integer = strWord.IndexOf("ay") 'used with iIndex to find the characters between "-" and "ay"
Dim strResult As String 'used to hold the finished product
If strWord.Substring(iIndex + 1, 1).ToLower = "w" Then
'if its a w then just remove '-way'
strResult = strWord.Remove(iIndex)
Else
'takes the letters between '-' and 'ay' and adds it to the front then removes the junk
strResult = strWord.Substring(iIndex + 1, iLastIndex - iIndex - 1) & strWord.Substring(0, iIndex)
End If
Return strResult
End Function
End Class
C#
Code: using System;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnEngtoPig_Click(object sender, EventArgs e)
{
//Checks to make sure text is entered
if (txtConvert.Text == null)
{
MessageBox.Show("No text was entered");
return;
}
//splits the entire sentence into words
string[] strWords = txtConvert.Text.Split(' ');
for (int i = 0; i < strWords.Length; i++)
{
//this loops through each word converting it to pig-latin
strWords[i] = EngToPig(strWords[i]);
}
//after each word is converted, it joins the string together and seperates
//each word by a space
txtOutput.Text = String.Join(" ", strWords);
}//end btnEngtoPig
private void btnPigtoEng_Click(object sender, EventArgs e)
{
//if there are no hyphens, then we can't translate
if (!txtConvert.Text.Contains("-"))
{
MessageBox.Show("This is not a valid Pig-Latin senence");
return;
}
//sepearte each word into a string array
string[] strWords = txtConvert.Text.Split(' ');
for (int i = 0; i < strWords.Length; i++)
{
//translate each word
strWords[i] = PigToEng(strWords[i]);
}
//join each translated word back to a sentence
txtOutput.Text = String.Join(" ", strWords);
}//end btPigtoEng
private string EngToPig(string strWord)
{
string chrVowel = null; //used to find our first vowel
string strSplit = null; //used to take the first part of the word and append at the end
string strResult; //holds our finished value
int iIndex = 0; //helps split the text at the vowel
for (int i = 0; i < strWord.Length; i++)
{
//this loops through each character to find the first vowel
chrVowel = strWord.Substring(i, 1);
switch (chrVowel.ToLower())
{
case "a":
case "e":
case "i":
case "o":
case "u":
case "y":
//if it's the first character only append -way to the end
if (i == 0)
return strWord + "-way";
//strSplit becomes what we attach to the end
strSplit = strWord.Substring(0, i).ToLower();
//this is going to be the position of the first vowel
iIndex = strWord.IndexOf(chrVowel);
//we want our new word to start at the vowel, then have everthing else added to the end with 'ay'
strResult = strWord.Substring(iIndex, strWord.Length - iIndex) + "-" + strSplit + "ay";
//return the translated word
return strResult;
}//end switch
}
MessageBox.Show("There are no vowels. Therefore a conversion cannot be done");
return "";
}//end function
private string PigToEng(string strWord)
{
int iIndex = strWord.IndexOf("-"); //used to find our split
int iLastIndex = strWord.IndexOf("ay"); //used with iIndex to find the characters between "-" and "ay"
string strResult = null; //used to hold the finished product
if (strWord.Substring(iIndex + 1, 1).ToLower() == "w")
{
//if its a w then just remove '-way'
strResult = strWord.Remove(iIndex);
}
else
{
//takes the letters between '-' and 'ay' and adds it to the front then removes the junk
strResult = strWord.Substring(iIndex + 1, iLastIndex - iIndex - 1) + strWord.Substring(0, iIndex);
}
return strResult;
}//end function
}//end form1
}
Wasn't as bad as I though it would be. I didnt try to make a GUI at all so don't hate on it. I simply did the program. It uses two functions. One to convert to Pig-Latin and another to convert to English.
Edit: Did it in C# as well for the heck of it.
(04-16-2011, 11:29 AM)The High Roller Wrote: I am good at VB, I just never focused on arrays. Promise you that, you know when pros can do such hard things and cant do the easy? Yes thats me.
You should brush up on arrays then. They are actually quite handy. Also, you didn't use any functions in yours. Thought I'd point that out. Your submission wasn't too bad though. Good job.
In yours, look at how it translates: chinese
(04-16-2011, 03:03 AM)Untouch Wrote: Seems pretty easy to do, well in java anyway.
Give it a shot
Posts: 1,106
Threads: 195
Joined: Sep 2010
Reputation:
17
(04-16-2011, 12:35 PM)KoBE Wrote:
Click here to download the projects (C# and VB.Net)
VB.Net
Code: Public Class Form1
'.Net Coding Challeng #1 by KoBE.
'Enjoy!
Private Sub btnEngtoPig_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEngtoPig.Click
'Checks to make sure text is entered
If txtConvert.Text = "" Then
MessageBox.Show("No text was entered")
Exit Sub
End If
'splits the entire sentence into words
Dim strWords() As String = txtConvert.Text.Split(" ")
For i = 0 To strWords.Length - 1
'this loops through each word converting it to pig-latin
strWords(i) = EngToPig(strWords(i))
Next
'after each word is converted, it joins the string together and seperates
'each word by a space
txtOutput.Text = Join(strWords, " ")
End Sub
Private Sub btnPigtoEng_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPigtoEng.Click
'if there are no hyphens, then we can't translate
If Not txtConvert.Text.Contains("-") Then
MessageBox.Show("This is not a valid Pig-Latin senence")
Exit Sub
End If
'sepearte each word into a string array
Dim strWords() As String = txtConvert.Text.Split(" ")
For i = 0 To strWords.Length - 1
'translate each word
strWords(i) = PigToEng(strWords(i))
Next
'join each translated word back to a sentence
txtOutput.Text = Join(strWords, " ")
End Sub
Private Function EngToPig(ByVal strWord As String) As String
Dim chrVowel As Char 'used to find our first vowel
Dim strSplit As String 'used to take the first part of the word and append at the end
Dim strResult As String 'holds our finished value
Dim iIndex As Integer 'helps split the text at the vowel
For i = 0 To strWord.Length - 1
'this loops through each character to find the first vowel
chrVowel = strWord.Substring(i, 1)
Select Case chrVowel.ToString.ToLower
Case "a", "e", "i", "o", "u", "y"
'if it's the first character only append -way to the end
If i = 0 Then Return strWord & "-way"
'strSplit becomes what we attach to the end
strSplit = strWord.Substring(0, i).ToLower
Exit For
End Select
Next
If chrVowel = "" Then
MessageBox.Show("There are no vowels. Therefore a conversion cannot be done")
Return ""
End If
'this is going to be the position of the first vowel
iIndex = strWord.IndexOf(chrVowel)
'we want our new word to start at the vowel, then have everthing else added to the end with 'ay'
strResult = strWord.Substring(iIndex, strWord.Length - iIndex) & "-" & strSplit & "ay"
'return the translated word
Return strResult
End Function
Private Function PigToEng(ByVal strWord As String) As String
Dim iIndex As Integer = strWord.IndexOf("-") 'used to find our split
Dim iLastIndex As Integer = strWord.IndexOf("ay") 'used with iIndex to find the characters between "-" and "ay"
Dim strResult As String 'used to hold the finished product
If strWord.Substring(iIndex + 1, 1).ToLower = "w" Then
'if its a w then just remove '-way'
strResult = strWord.Remove(iIndex)
Else
'takes the letters between '-' and 'ay' and adds it to the front then removes the junk
strResult = strWord.Substring(iIndex + 1, iLastIndex - iIndex - 1) & strWord.Substring(0, iIndex)
End If
Return strResult
End Function
End Class
C#
Code: using System;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnEngtoPig_Click(object sender, EventArgs e)
{
//Checks to make sure text is entered
if (txtConvert.Text == null)
{
MessageBox.Show("No text was entered");
return;
}
//splits the entire sentence into words
string[] strWords = txtConvert.Text.Split(' ');
for (int i = 0; i < strWords.Length; i++)
{
//this loops through each word converting it to pig-latin
strWords[i] = EngToPig(strWords[i]);
}
//after each word is converted, it joins the string together and seperates
//each word by a space
txtOutput.Text = String.Join(" ", strWords);
}//end btnEngtoPig
private void btnPigtoEng_Click(object sender, EventArgs e)
{
//if there are no hyphens, then we can't translate
if (!txtConvert.Text.Contains("-"))
{
MessageBox.Show("This is not a valid Pig-Latin senence");
return;
}
//sepearte each word into a string array
string[] strWords = txtConvert.Text.Split(' ');
for (int i = 0; i < strWords.Length; i++)
{
//translate each word
strWords[i] = PigToEng(strWords[i]);
}
//join each translated word back to a sentence
txtOutput.Text = String.Join(" ", strWords);
}//end btPigtoEng
private string EngToPig(string strWord)
{
string chrVowel = null; //used to find our first vowel
string strSplit = null; //used to take the first part of the word and append at the end
string strResult; //holds our finished value
int iIndex = 0; //helps split the text at the vowel
for (int i = 0; i < strWord.Length; i++)
{
//this loops through each character to find the first vowel
chrVowel = strWord.Substring(i, 1);
switch (chrVowel.ToLower())
{
case "a":
case "e":
case "i":
case "o":
case "u":
case "y":
//if it's the first character only append -way to the end
if (i == 0)
return strWord + "-way";
//strSplit becomes what we attach to the end
strSplit = strWord.Substring(0, i).ToLower();
//this is going to be the position of the first vowel
iIndex = strWord.IndexOf(chrVowel);
//we want our new word to start at the vowel, then have everthing else added to the end with 'ay'
strResult = strWord.Substring(iIndex, strWord.Length - iIndex) + "-" + strSplit + "ay";
//return the translated word
return strResult;
}//end switch
}
if (chrVowel == null)
{
MessageBox.Show("There are no vowels. Therefore a conversion cannot be done");
}//end if
return "";
}//end function
private string PigToEng(string strWord)
{
int iIndex = strWord.IndexOf("-"); //used to find our split
int iLastIndex = strWord.IndexOf("ay"); //used with iIndex to find the characters between "-" and "ay"
string strResult = null; //used to hold the finished product
if (strWord.Substring(iIndex + 1, 1).ToLower() == "w")
{
//if its a w then just remove '-way'
strResult = strWord.Remove(iIndex);
}
else
{
//takes the letters between '-' and 'ay' and adds it to the front then removes the junk
strResult = strWord.Substring(iIndex + 1, iLastIndex - iIndex - 1) + strWord.Substring(0, iIndex);
}
return strResult;
}//end function
}//end form1
}
Wasn't as bad as I though it would be. I didnt try to make a GUI at all so don't hate on it. I simply did the program. It uses two functions. One to convert to Pig-Latin and another to convert to English.
Edit: Did it in C# as well for the heck of it.
You should brush up on arrays then. They are actually quite handy. Also, you didn't use any functions in yours. Thought I'd point that out. Your submission wasn't too bad though. Good job.
In yours, look at how it translates: chinese
(04-16-2011, 03:03 AM)Untouch Wrote: Seems pretty easy to do, well in java anyway. Give it a shot
LOL, KoBE, let me post a challenge!
Posts: 341
Threads: 34
Joined: Nov 2010
Reputation:
8
(04-16-2011, 01:56 PM)The High Roller Wrote: LOL, KoBE, let me post a challenge!
Feel free to do what you want. I hope you didn't take my comment in a negative light. I do however agree with Untouch's comment "(arrays) are very effective and can be powerful if used correct". You should definitely learn to use them.
Posts: 5,793
Threads: 268
Joined: Sep 2010
Reputation:
85
04-16-2011, 02:26 PM
(This post was last modified: 04-16-2011, 02:35 PM by AceInfinity.)
(04-16-2011, 11:17 AM)KoBE Wrote: Pig latin is not a real language. It's just a play on words. To form a word in pig latin you take a word such as:
Baseball...
you cut it off at the 'a' because it's the first vowel. Making it:
aseball...
then you put the letter back on to the end and add 'ay'. Making it:
aseball-bay.
Other ex:
Tennis -> ennis-tay
Soccer -> occer-say
Dinner -> inner-day
If the word starts with a vowel, you just put 'way' on the end.
Ex:
apple-way
english-way
arm-way
Hope that clears it up. Sorry, I thought everyone would have known what pig latin was that's why I chose this.
No, I guess i'm the odd one out lol. What if there is a word like "Great" would it cut out at "eat" since e is the first vowel?
Edit: downloading your project to see for myself.
Hmm it came out as "eat-gray"??
Update: basically what i've got is that if it's "Keep" the first vowel is "e" so it would be "eep" ... add "ay" onto the end, which makes it "eep-ay" and since the first letter that was cut out was a "K" that would make it "eep-kay"? Is that all there is in pig latin? "crwth" with no vowels came out as "h-ay" for me. which means nothing was appended to the "ay" but it still took the last letter as "h" even though "t" isn't a vowel.
|