您的位置:首页 > 产品设计 > UI/UE

symbian 字符串描述符格式化format输出转换

2010-01-27 10:15 579 查看
 

Formatting text

The following code fragments illustrate the various possibilities of
Format()

.

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]





内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息