0

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

3
Contributors
6
Replies
12
Views
6 Years
Discussion Span
Last Post by alex55
Featured Replies
  • An if statement. If string[n] == '#' then split the string. Also, take a look at [URL="http://www.daniweb.com/forums/thread317317.html"]this code[/URL] that someone else wrote. If you can understand it, you can adapt it. Read More

  • [QUOTE=alex55;1356854]how would you go about splitting it? sorry im new im really trying to learn this[/QUOTE] I'm going to quote the code right out of the post I linked and modify it slighly. [code] int length=strlen(sentence); int check=0; for(int i=length-1; i>=0; i--){ if(sentence[i]!=' ' && i != 0){ check++; } … Read More

0

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

string middle_last;
1

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.

0

how would you go about splitting it?

sorry im new im really trying to learn this

1

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 by kes166: n/a

This question has already been answered. Start a new discussion instead.
Please be thoughtful and detailed and be sure to adhere to our posting rules.