03.01.2013 Views

Chapter 1

Chapter 1

Chapter 1

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

SetLength() allows the length to be specified to anything within range 0 to MaxLength(),<br />

and SetMax() sets the length to the maximum length.<br />

Various Fill() functions allow a descriptor to be filled with data quickly.<br />

5.3.6 Manipulating Data<br />

TDes's Copy() function copies data to the descriptor, starting at the beginning, while<br />

Append() can copy additional data to the descriptor, starting where the existing data stops.<br />

There are variants of the Copy()function that perform case or accent folding.<br />

Insert() inserts data into any position, pushing up subsequent characters toward the end<br />

of the string. Delete() deletes any sequence of characters, moving down subsequent<br />

characters to close the gap. Replace() overwrites characters in the middle of a string.<br />

5.3.7 Letter Manipulation<br />

TDes's Fold(), Collate(), LowerCase(), UpperCase(), and Capitalize() functions all<br />

manipulate characters in place.<br />

Note<br />

Collating an individual string isn't very useful, and TDes::Collate() is<br />

therefore deprecated.<br />

5.3.8 Trimming and Justification<br />

TDes's Trim() functions shave whitespace from either or both ends of a string.<br />

Justify() performs left, right, center, or no justification and allows the fill character to be<br />

overridden. Various AppendJustify()functions append and justify simultaneously.<br />

Note<br />

Justify() is not really very useful, since real text justification is done at the<br />

GUI level, not the individual string level.<br />

5.3.9 Formatting<br />

TDes::AppendFormat() is a bit like C sprintf(): it takes a format string and a variable<br />

argument list and appends the result to an existing descriptor. Functions such as Format()<br />

are implemented in terms of this one as was CConsoleBase::Printf(), which we saw in<br />

hellotext and strings.<br />

Many lower-level functions exist to support AppendFormat(): various Num() functions<br />

convert numbers into text, and corresponding AppendNum() functions append converted<br />

numbers onto an existing descriptor. For simple conversions, the AppendNum() functions<br />

are much more efficient than using AppendFormat() with a suitable format string.<br />

In C, scanning functions are provided by sscanf() and packaged variants such as<br />

scanf(), fscanf() and so on. Similar functions are available in Symbian OS, through<br />

TLex and associated classes, which scan data held in TDesCs. These functions are<br />

relatively specialized and it was not thought appropriate to implement them directly in<br />

TDesC.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!