Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Changes between Version 11 and Version 12 of TutTextConversions

Show
Ignore:
Author:
kris (IP: 68.122.193.31)
Timestamp:
04/17/07 02:50:47 (17 years ago)
Comment:

updated

Legend:

Unmodified
Added
Removed
Modified
  • TutTextConversions

    v11 v12  
    77== Number Conversions ==  
    88 
     9lightweight numeric conversions are located in modules tango.text.convert.Integer and tango.text.convert.Float: 
    910{{{ 
    1011#!d 
    11  
    1212    // from text to numbers 
    13  
    14     int integer = Atoi.parse("302"); 
    15     double double_ = Double.parse("3.14592"); 
    16     real real_ = DGDouble.parse("1.41421"); // for extended accuracy 
     13    int i = Integer.parse("302"); 
     14    real d = Float.parse("3.14159"); 
    1715 
    1816    // and from numbers to text 
    19  
    20     char [64] intBuffer; 
    21     char [64] floatBuffer; 
    22     char [64] realBuffer; 
    23  
    24     char [] intString = Integer.format(intBuffer,32 ); 
    25     char [] floatString = Double.format(floatBuffer,45 ); 
    26     char [] realString = DGDouble.format(realBuffer,32.65798,3 ); 
    27  
     17    char[] intString = Integer.toUtf8(32); 
     18    char[] floatString = Float.toUtf8(3.14159); 
    2819}}} 
    2920 
    3021== Unicode ==  
    3122We will continue with the other most common types, which would be converting between different unicode representations.  Sticking to tango tradition of using 'toUtf8' to mean 'give me a string representation' , tango.text.conversion.Unicode contains templated methods to convert between different encodings including: 
    32  
    3323{{{ 
    3424#!d 
    35  
    36     char  [] eight = Unicode.toUtf8("test"); 
    37     wchar [] sixteen  = Unicode.toUtf16("test"); 
    38     dchar [] thirtyTwo = Unicode.toUtf32("test"); 
    39  
     25    char[] eight = Unicode.toUtf8("test"); 
     26    wchar[] sixteen  = Unicode.toUtf16("test"); 
     27    dchar[] thirtyTwo = Unicode.toUtf32("test"); 
    4028}}} 
    4129 
    42 == Formating ==  
     30== Formatting ==  
    4331 
    44 Probably the most useful class in the conversion line-up is the 'Formatter' class, which formats a string based on C# style syntax via the 'format' method. 
    45  
     32Probably the most useful class in the conversion line-up is the 'Layout' class, which formats a string based on C# style syntax. 
    4633{{{ 
    4734#!d 
    48  
    49     char [] str = Formatter.format("{0} sells {1} by the {2}","Sally","shells","seashore"); 
    50  
     35    auto layout = new Layout!(char); 
     36    char[] str = layout ("{} sells {} by the {}","Sally", "shells", "seashore"); 
    5137}}} 
    5238 
    5541== Summary == 
    5642 
    57 The tango.text.convert package contains a set of quality classes for both precison converting ( DGDouble ) , and every day converting ( Atoi, Double, Integer ).  The convention of using parse() and format() among all the classes makes it easy to just dive right in with a conversion class. 
     43The tango.text.convert package contains a set of classes for everyday numeric convertion (Float, Integer).  The convention of using parse() and format() among all the classes makes it easy to just dive right in with a conversion class. 
    5844 
    59 Other more exotic classes exist for converting dates, and for inserting Unicode BOM's which you can find in the [wiki:ChapterConversions Reference Manual - Conversions chapter]. 
     45Other more exotic classes exist for converting dates, handling Unicode BOM, etc. They can be located via the [wiki:ChapterConversions Reference Manual - Conversions chapter]. 
    6046 
    6147