StrOps::Lines( StrBuf &, char *[], int )

Break a string apart at line breaks.

Virtual?

No

 

Class

StrOps

 

Arguments

StrBuf &o

the input string

 

char *vec[]

the output array

 

int maxVec

the maximum number of lines to handle

Returns

int

the actual number of lines handled

Notes

This function handles all types of line breaks: “\r”, “\n”, and “\r\n”.

Example

StrBuf o = StrBuf();
o.Set( "abc\ndef\nghi\n" );

printf( "Input StrBuf:\n%s\n", o.Text() );

char *vec[4];
int l = StrOps::Lines( o, vec, 4 );

for ( ; l ; l-- )
{
    printf( "Line %d: %s\n", l, vec[l-1] );
}

Executing the preceding code produces the following output:

Input StrBuf:
abc
def
ghi

Line 3: abc
Line 2: def
Line 1: ghi