Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. Questions about string manipulation

Questions about string manipulation

Scheduled Pinned Locked Moved Managed C++/CLI
tutorialdata-structureshelp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TabascoSauce
    wrote on last edited by
    #1

    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**
    
    N 1 Reply Last reply
    0
    • T TabascoSauce

      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**
      
      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      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 as array<Char>^

      Navaneeth How to use google | Ask smart questions

      modified on Tuesday, April 21, 2009 5:37 AM

      T 1 Reply Last reply
      0
      • N N a v a n e e t h

        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 as array<Char>^

        Navaneeth How to use google | Ask smart questions

        modified on Tuesday, April 21, 2009 5:37 AM

        T Offline
        T Offline
        TabascoSauce
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups