So i have a string say string A = junk#crap
i want to separate it to separate strings
b=junk
c=crap

how would i go about doing that while throwing out the #?

just a normal string like i declared it in my program its

string middle_last;

An if statement.

If string[n] == '#' then split the string.

Also, take a look at this code that someone else wrote. If you can understand it, you can adapt it.

how would you go about splitting it?

sorry im new im really trying to learn this

how would you go about splitting it?

sorry im new im really trying to learn this

I'm going to quote the code right out of the post I linked and modify it slighly.

int length=strlen(sentence);
 int check=0;    
 for(int i=length-1; i>=0; i--){
        if(sentence[i]!=' ' && i != 0){
            check++;        
        }
        else{
            for(int j=i; j<(check+i); j++)
                cout<<sentence[j+1];
                cout<<" ";
                check=0;        
        }
 }

sentence = junk#crap

You will still need to modify this code, but once you understand it, it'll be easy to see. This code cout's where you would actually need to save the values elsewhere instead of just displaying them.

Edited 6 Years Ago by kes166: n/a

This question has already been answered. Start a new discussion instead.