System.Text.CFormat

CFormat Class


Provides C-style string formatting.

Definition

public class CFormat: Object

Members Table

MethodDescription
Equals(Inherited from Object)
Format
GetHashCode(Inherited from Object)
GetTypeName(Inherited from Object)
MemberwiseClone(Inherited from Object)
ReferenceEquals(Inherited from Object)
ToString(Inherited from Object)

Inheritance Hierarchy

Object
CFormat

Examples

The following example shows a small range of the powerfull C-style formatting features:

using System;

using System.Text;

 

class MySample
{
  static void Main()
    {
    // Print a simple integer
    int i= 12;
    Debug.Trace( CFormat.Format( "i=%d", i ) );
 

    // Print an hexadecimal integer
    Debug.Trace( CFormat.Format( "hex number=0x%08X (=%d)",
                                 34567891, 34567891 ) );


    // Print floating point numbers with proper rounding
    double f1= 56.16548664545;
    Debug.Trace( CFormat.Format( "f2=%f", f1 ) );
    Debug.Trace( CFormat.Format( "f1=%1.2f", f1 ) );
    Debug.Trace( CFormat.Format( "f1 in E format=%E", f1 ) );
 

    // prints 10 random numbers with proper alignment
    int n= 10;
    for( int k= 1; k <= n; ++k )
      {
      int rnd= Math.Random( 1, 200 );
      if( Math.Random(0,1) == 0 )
        rnd= -rnd;

      string str= CFormat.Format( "Random %02d/%d : %4.d", k, n, rnd );
              
      Debug.Trace(str);
      }     
    }
}

 

This example outputs the following text in the Debug console:

i=12
hex number=0x020F76D3 (=34567891)
f2=56.165487
f1=56.17
f1 in E format=5.616549E+01
Random 01/10 : -190
Random 02/10 :   91
Random 03/10 : -143
Random 04/10 :  -29
Random 05/10 :  -76
Random 06/10 :   91
Random 07/10 : -102
Random 08/10 :  186
Random 09/10 :   24
Random 10/10 :  113


Please note that using CFormat will add between 3 and 4 KB to the final SWF file. CFormat is not a lightweight algorithm.

Class Information

NamespaceSystem.Text
Librarycformat.scl
Library Version1.0.0.1393
© 2004-2005 GlobFX Technologies. All rights reserved.