symbian 字符串描述符格式化format输出转换
2010-01-27 10:15
579 查看
Formatting text
The following code fragments illustrate the various possibilities ofFormat()
.
The behaviour is the same for the build independent variant,
TDes
,
replacing
_LIT16
with
_LIT
, and
TBuf16
with
TBuf
.
TBuf16<256> tgt; ... _LIT16(KFormat1,"[%b %c %d %o %u %x]"); tgt.Format(KFormat1,65,65,65,65,65,65);//generates: ... //[1000001 A 65 101 65 41] ... _LIT16(KFormat2,"[%04x]"); // pad char="0", field width=4 tgt.Format(KFormat2,65); //generates: ... //[0041] ... _LIT16(KFormat3,"[%4x]"); // pad char=default, field width=4 tgt.Format(KFormat3,65); //generates: ... //[ 41] ... // Note use of blanks as default pad chars. ... _LIT16(KFormat4,"[%*x]"); // fixed field width, taken from the arguments list tgt.Format(KFormat4,4,65); //generates: ... //[ 41] ... ... _LIT16(KFormat5,"[%+$4d.00 %S]"); // pad char="$", field width=4, right aligned _LIT16(KOver,"over"); tgt.Format(KFormat5,65,&KOver); //generates: ... //[$$65.00 over] ... _LIT16(KFormat6,"[%+4d.00 %S]"); // pad char=default, field width=4 tgt.Format(KFormat6,65,&KOver); //generates: ... //[ 65.00 over] ... // note no pad char specified, defaults ... // to blank ... _LIT16(KFormat7,"[% 4d.00 %S]"); // pad char=" ", field width=4, alignment=default tgt.Format(KFormat7,65,&KOver); //generates: ... //[ 65.00 over] ... // note default right hand alignment and ... // blank pad char ... _LIT16(KFormat8,"[%+0*S]"); // right aligned, pad char="0", fixed field width _LIT16(KFred,"fred"); tgt.Format(KFormat8,10,&KFred); //generates: ... //[000000fred] ... // Note: 10 characters generated ... _LIT16(KFormat9,"[%=*6x]"); // centre aligned, pad char taken from arguments list, field width=6 tgt.Format(KFormat9,'*',65); //generates: ... //[**41**] ... _LIT16(KFormat10,"[%+**d]"); // right aligned, pad char and field width taken from arguments list tgt.Format(KFormat10,'.',10,(-65)); //generates: ... //[.......-65] ... _LIT16(KFormat11,"[%-A4p]"); // left aligned, field width=4, pad char="A" tgt.Format(KFormat11,65); //generates ... //[AAAA] ... // and makes no use of the argument list ... _LIT16(KFormat12,"[%m]"); //generates: tgt.Format(KFormat12,4660); // the char '[' ... // followed by a byte with 0x12 ... // followed by a byte with 0x34 ... // followed by the char ']' _LIT16(KFormat13,"[%M]") tgt.Format(KFormat13,4660); //generates: ... // the char '[' ... // followed by a byte with 0x00 ... // followed by a byte with 0x00 ... // followed by a byte with 0x12 ... // followed by a byte with 0x34 ... // followed by the char ']' ... _LIT16(KFormat14,"[%w]"); //generates: tgt.Format(KFormat14,4660); // the char '[' ... // followed by a byte with 0x34 ... // followed by a byte with 0x12 ... // followed by the char ']' .. _LIT16(KFormat15,"[%w]"); //generates: tgt.Format(KFormat15,4660); // the char '[' ... // followed by a byte with 0x34 ... // followed by a byte with 0x12 ... // followed by a byte with 0x00 ... // followed by a byte with 0x00 ... // followed by the char ']' ... _LIT16(KFormat16,"[%6.2e]"); tgt.Format(KFormat16,3.4555); //generates: ... //[3.46E+00] _LIT16(KFormat17,"[%6.2f]"); tgt.Format(KFormat17,3.4555); //generates: ... //[ 3.46] _LIT16(KFormat18,"[%6.2g]"); tgt.Format(KFormat18,3.4555); //generates: //[3.4555] ... // Variable argument positions _LIT16(KFormat19,"[%d %d]"); // implicit ordering tgt.Format(KFormat19,9,5); // generates: ... // [9 5] ... _LIT16(KFormat20,"[%$2$d %$1$d]"); // explicit ordering tgt.Format(KFormat20,9,5); // generates: ... // [5 9] ... _LIT16(KFormat21,"[%$1$d %$2$d]"); // explicit ordering (same as the implicit order) tgt.Format(KFormat21,9,5); // generates: ... // [9 5] // Using argument blocks (a many-to-one mapping between arguments and conversion specifiers) _LIT16(KFormat22,"[%0*d %d %d]"); // implicit ordering tgt.Format(KFormat22,3,9,5,12); // generates: ... // [009 5 12] ... _LIT16(KFormat23,"[%$2$d %$1$0*d %d]"); // mixed explicit and implicit ordering tgt.Format(KFormat23,3,9,5,12); // generates: ... // [5 009 12] ... _LIT16(KFormat24,"[%$3$d %$1$0*d %$2$d]"); // explicit ordering tgt.Format(KFormat24,3,9,5,12); // generates: ... // [12 009 5]
[/code]
[/code]
相关文章推荐
- Format() 函数用于将数据转换为格式化的字符串输出
- Python - 格式化(format())输出字符串 详解 及 代码
- Js中字符串十六进制格式化转换和对齐输出
- Symbian字符串 描述符 转换方法汇总
- MessageFormat对象实现格式化字符串输出,类似C#中的string.format方法
- 浅谈Python 字符串格式化输出(format/printf)
- Python - 格式化(format())输出字符串 详解 及 代码
- AS3原生JSON输出字符串描述时的格式化
- java中实现与.net的format格式化字符串输出
- Python:字符串格式化输出(format/printf)
- 浅谈Python 字符串格式化输出(format/printf)
- 格式化输出字符串之Format、IFormattable、IFormatProvider、ICustomFormatter
- 神一般的 str.format() 函数 - Python 字符串格式化转换(转载)
- Python - 格式化(format())输出字符串 详解 及 代码
- iphone ios 字符串NSString格式化format输出
- iphone ios 字符串NSString格式化format输出
- Python 字符串格式化输出(format/printf)
- String.format() / 字符串拼接格式化输出数据
- 格式化format()输出字符串
- MessageFormat对象实现格式化字符串输出,类似C#中的string.format方法