how to cut a string buffer?
i have string buffer like "delmeABCDEFGH".And what i would like to do is to cut delme off the string so that the string will become "ABCDEFGH".Can anyone tell me which syntax should be used here?Something like strstr...
[219 byte] By [
kurumi] at [2007-11-19 22:48:21]

# 1 Re: how to cut a string buffer?
Depends on a number of things. What type of string is it? Are the characters that you want to cut always the same or the same length?
GCDEF at 2007-11-10 23:32:59 >

# 2 Re: how to cut a string buffer?
It is char type and it differs everytime except the prefix "delme"!
kurumi at 2007-11-10 23:33:54 >

# 3 Re: how to cut a string buffer?
If it's a plain char array, you can use strcpy or variants to start copying the string from character 5 till the end into a new character array.
If you convert your string to an std::string, you can use the erase method to erase the first 5 characters.
Marc G at 2007-11-10 23:35:03 >

# 4 Re: how to cut a string buffer?
i think instead of using strcpy you can use strncpy . this is much easy for you or go for string which is always good for you.
# 5 Re: how to cut a string buffer?
you can use strcpy or variants to start copying the string from character 5 till the end into a new character array.
How do you do this with strcpy?
kurumi at 2007-11-10 23:37:04 >

# 6 Re: how to cut a string buffer?
have a look for strncpy
int i;
cin>>i;// How many character you want to left
strncpy (//buffer whr you want to copy,//Buffer from whr you want to copy +i(Position from where you want to copy,how much you want to copy);
same you can use with memcpy
Thanx
# 7 Re: how to cut a string buffer?
How do you do this with strcpy?
Something like this:
const char *arr="delmeABCDEFGH";
char szResult[MAX_PATH]={0};
int Len = strlen("delme");
strcpy(szResult,&arr[Len] );
Cheers
# 8 Re: how to cut a string buffer?
Using the previous example, I think what you want is
const char *arr="delmeABCDEFGH";
char szResult[MAX_PATH]={0};
strcpy(szResult, arr+5);
arr+5 just starts the copy 5 bytes in instead of at the beginning.
I don't see how strncpy or memcpy would help in this case.
GCDEF at 2007-11-10 23:40:05 >

# 9 Re: how to cut a string buffer?
oh,all works...Thanks a lot,all of friends!Learn a lot!
kurumi at 2007-11-10 23:41:06 >

# 10 Re: how to cut a string buffer?
And the C++ approach using std::string (as Marc G mentioned) and CStringT (MFC and ATL):
// std::string
string str( "delmeABCDEFGH" );
str.erase( 0, 5 );
// CString
CString str( _T("delmeABCDEFGH") ); //NOTE: _T macro used for ANSI and UNICODE compatibility
str.Delete( 0, 5 );
Arjay at 2007-11-10 23:42:07 >

# 11 Re: how to cut a string buffer?
Using the previous example, I think what you want is
const char *arr="delmeABCDEFGH";
char szResult[MAX_PATH]={0};
strcpy(szResult, arr+5);
arr+5 just starts the copy 5 bytes in instead of at the beginning.
I don't see how strncpy or memcpy would help in this case.
Did u tried this one with yourself if not Please go ahead
char str[100] = "helloDummy ABCDEFGH";
int i;
char str1[100];
memset(str1,0,sizeof(str1));
cout<<"Original String is \n" <<str<<endl<<"Enter how many Character you want to extract \n";
cin>>i;
strncpy(str1,str+i,strlen(str)-i);
cout<<str1;