Link to home
Start Free TrialLog in
Avatar of Dj_Fx8
Dj_Fx8

asked on

Fill a String

Hi

Is there a way to fill a string with say 6 spaces ie
CString str= Fill(6, " ")
or do I have to write it myself
Avatar of Member_2_1001466
Member_2_1001466

It would be easier for a char* using memset. Add one additional space which you replace with the terminating 0 afterwards:

char* cs = new char[7];
memset (cs, ' ', 7);
*cs[6] = '0x0';

CString str = cs;
delete [] cs;
Or

void Fill  (CString& str, char cFill, int nCount)
{
    char* cs = str.GetBufferSetLength (nCount);
    memset (cs, cFill, nCount);
    str.ReleaseBuffer (nCount);
}
Avatar of AndyAinscow
CString s("      ");  //s contains 6 spaces
ASKER CERTIFIED SOLUTION
Avatar of Jaime Olivares
Jaime Olivares
Flag of Peru image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Dj_Fx8

ASKER

Hi
Thanks for all your replies, I'm will award the points to Jaime as his answer is a simple one line of code and best answers my question
Those points are walking too slow. ;-P
Thanks anyway!