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 #?

It really depends, are you talking about a string object or are you talking about a c-string?

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.

I think i see it now thank you very much

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.