本文整理汇总了C++中TString::SetLength方法的典型用法代码示例。如果您正苦于以下问题:C++ TString::SetLength方法的具体用法?C++ TString::SetLength怎么用?C++ TString::SetLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TString
的用法示例。
在下文中一共展示了TString::SetLength方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CSVString
void CSVString( const TStringVector &sv, TString &string, char adelimiter )
{
TString word;
int i;
int n = sv.size();
int totallength = 0;
// int pos = 0;
char *pos;
if( sv.size()==0 ) {
string = "\"\"";
return;
}
for( unsigned int i=0; i<n; i++ )
{
word = CSVString( sv[i], adelimiter );
totallength += word.Length();
}
if( n>0 )
totallength += n-1;
string.SetLength( totallength );
pos = string.c_str();
for( unsigned int i=0; i<n; i++ )
{
word = CSVString( sv[i], adelimiter );
strcpy( pos, word.c_str() );
pos += word.Length();
if( i<(n-1) ) {
*pos = adelimiter;
pos++;
}
}
}
示例2: DecodeCSVString
void DecodeCSVString( TStringVector &strings, const TString& astring, char adelimiter )
{
TString str;
str.SetLength( astring.Length() );
strings.clear();
if( astring.Length()==0 )
return;
enum { normal, parenthesis } state;
state = normal;
const char *beg = astring.c_str();
const char *c = beg;
char *destbeg = str.c_str();
char *dest = destbeg;
while( *c )
{
switch( state )
{
case normal:
switch( *c )
{
case '"':
state = parenthesis;
c++;
break;
default:
if( *c == adelimiter )
{
strings.push_back( TString( destbeg, dest-destbeg ) );
dest = destbeg;
}
else {
*dest = *c;
dest++;
}
c++;
}
break;
case parenthesis:
if( *c == '"' )
{
c++;
state = normal;
}
else {
*dest = *c;
c++;
dest++;
}
break;
default:
strings.clear();
/* TODO : Nen� upln� jasn�, zda v p��pad� failu smazat to, co se dosud ud�lalo... */
throw TException( "Unknown error in DecodeCSVString." );
}
}
strings.push_back( TString( destbeg, dest-destbeg ) );
unsigned int nstrings = strings.size();
unsigned int ui;
for( ui=0; ui<nstrings; ui++ )
ReplaceHexFormWithOrdinals( strings[ui] );
}