Jump to content

Recommended Posts

Posted

How would i select a letter in a string and make it its own string? So say if i wanted to use the letter "a" in Snakey and make it its own string or even just have an if statement that uses the letter you select.

Posted

Hmmm not really what im after say i have "string x" and x=snakey how do i use the a as a seperate string. So i'll have int x = snakey then i'll make int y which will = a.

P.S. i dont no what x is at the start it gets entered as an input and i use each letter individually if that helps any.

Posted

I'm sure there's a built in function for it, I have done it in Java, but not C++, sorry.

    string str1( "Alpha Beta Gamma Delta" );
    unsigned int loc = str1.find( "Omega", 0 );
    if( loc != string::npos )
      cout << "Found Omega at " << loc << endl;
    else
      cout << "Didn't find Omega" << endl;

That does what you want on the side... just change the "Omega" to the character, and use the character position that is returned to substring(Java) whatever you want out.

Read under the "find" command here:

http://www-control.eng.cam.ac.uk/~pcr20/ww...ng_details.html

Posted

easier way would be to do a loop then you could loop through for any thing.

something like:

while stringx != '0'{

if stringx = x

strcpy( stringx, newString);

i++;

}

just off the top of my head, this wont work of course but it gives you an idea.

Posted
easier way would be to do a loop then you could loop through for any thing.

something like:

while stringx != '0'{

if stringx = x

strcpy( stringx, newString);

i++;

}

just off the top of my head, this wont work of course but it gives you an idea.

Wow, just wow... that's so wrong.

Posted

#include <string>

using namespace std;

string word1 = "snakey";

string word2 = "";

for(int x=0; x<word1.length(); x++)

    if(word1[ x ] == 'a')

          word2 = word1[ x ];

  • 1 month later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...