Questions about string manipulation
-
Hey guys, thanks for looking at my questions! First off, I am making a program that changes words into pig-latin form, here is an explanation of that: If a words starts with a vowel (including y), simply add -way to the end of the word (ex. "alphabet" would be alphabet-way). If a word starts with a consonant, move the section of the word up till the first vowel and put it at the end with "ay" attatched to it (ex. "lame" would be "ame-lay" and glucose would be "ucose-glay") On to the questions: I'm having some trouble figuring out how to determine the length of a word to a vowel. An example would be that the length of the word "Chair" up to the first vowel is 2. Also, I am having trouble using the String::Compare method to determine if a word even starts with a vowel (see code block at the bottom). I believe the syntax is String::Compare(string1, subscript1, string2, subscript2, count) and it returns a value of 0 if string1 is equivalent to string2, please correct me if I am wrong. I used an array containing all of the vowels and used it as string2 and had the word to compare it it to as string1 with the subscripts and count set up accordingly but it does not seem to return a value as I expected. Ok, I realize this probably made no sense without any code, so here is what I have so far (problem areas bolded):
private: System::Void button1\_Click(System::Object^ sender, System::EventArgs^ e) { //Variables String ^transformy = ""; //User input from text box String ^transformed = ""; //Label displaying transformed word String ^beginning = ""; //Beginning of transformed word String ^end = ""; //End of transformed word array<String ^>^vowels = {"a", "e", "i", "o", "u", "y"}; //Vowels int VowelOrNot = 0; //See code int toVowel = 0; //Distance to first vowel int toEnd = 0; //Distance from vowel to end of word //Get user input from uIn text box transformy = Convert::ToString(uIn->Text); **//Determine if the first letter is a vowel by comaring the first letter of user input to vowels array VowelOrNot = String::Compare(transformy, 0, Convert::ToString(vowels), 0, 1);; if (VowelOrNot == 0) { //If VowelOrNot says that the first letter is equal, then simply add -way to the end of the word** transformed = String::Concat(transformy, "-way"); //Output the new word in the pOut Label pOut->Text = Convert::ToString(transformed); } else { **//Det**
-
Hey guys, thanks for looking at my questions! First off, I am making a program that changes words into pig-latin form, here is an explanation of that: If a words starts with a vowel (including y), simply add -way to the end of the word (ex. "alphabet" would be alphabet-way). If a word starts with a consonant, move the section of the word up till the first vowel and put it at the end with "ay" attatched to it (ex. "lame" would be "ame-lay" and glucose would be "ucose-glay") On to the questions: I'm having some trouble figuring out how to determine the length of a word to a vowel. An example would be that the length of the word "Chair" up to the first vowel is 2. Also, I am having trouble using the String::Compare method to determine if a word even starts with a vowel (see code block at the bottom). I believe the syntax is String::Compare(string1, subscript1, string2, subscript2, count) and it returns a value of 0 if string1 is equivalent to string2, please correct me if I am wrong. I used an array containing all of the vowels and used it as string2 and had the word to compare it it to as string1 with the subscripts and count set up accordingly but it does not seem to return a value as I expected. Ok, I realize this probably made no sense without any code, so here is what I have so far (problem areas bolded):
private: System::Void button1\_Click(System::Object^ sender, System::EventArgs^ e) { //Variables String ^transformy = ""; //User input from text box String ^transformed = ""; //Label displaying transformed word String ^beginning = ""; //Beginning of transformed word String ^end = ""; //End of transformed word array<String ^>^vowels = {"a", "e", "i", "o", "u", "y"}; //Vowels int VowelOrNot = 0; //See code int toVowel = 0; //Distance to first vowel int toEnd = 0; //Distance from vowel to end of word //Get user input from uIn text box transformy = Convert::ToString(uIn->Text); **//Determine if the first letter is a vowel by comaring the first letter of user input to vowels array VowelOrNot = String::Compare(transformy, 0, Convert::ToString(vowels), 0, 1);; if (VowelOrNot == 0) { //If VowelOrNot says that the first letter is equal, then simply add -way to the end of the word** transformed = String::Concat(transformy, "-way"); //Output the new word in the pOut Label pOut->Text = Convert::ToString(transformed); } else { **//Det**
TabascoSauce wrote:
//Determine if the first letter is a vowel by comaring the first letter
bool startsWithVowel = (Array::IndexOf(vowels, transformy->Substring(0,1), 0) == -1) ? false : true;
if(startsWithVowel)
{
.....
}TabascoSauce wrote:
//Determine how long a word is up to first vowel
transformy->IndexOfAny(vowels);
You need to make
vowels
asarray<Char>^
Navaneeth How to use google | Ask smart questions
modified on Tuesday, April 21, 2009 5:37 AM
-
TabascoSauce wrote:
//Determine if the first letter is a vowel by comaring the first letter
bool startsWithVowel = (Array::IndexOf(vowels, transformy->Substring(0,1), 0) == -1) ? false : true;
if(startsWithVowel)
{
.....
}TabascoSauce wrote:
//Determine how long a word is up to first vowel
transformy->IndexOfAny(vowels);
You need to make
vowels
asarray<Char>^
Navaneeth How to use google | Ask smart questions
modified on Tuesday, April 21, 2009 5:37 AM
Thanks N a v a n e e t h! **Edit Ok, I got it now! Thanks very much!
modified on Tuesday, April 21, 2009 10:06 PM