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

Leave Comments, Critiques, and Suggestions Here?

Find, Replace and friends

The tango.text.Util is a collection of templated helper functions. The module doc (previous link) has a summary and usage examples. The contained functions can handle UTF8/16/32.

Note: you can also use generic array functions on a string. See tango.core.Array

import tango.text.Util;
void test1(){
  locate( "abcdef", "cd" ); // returns 2
}

tango.text.Util also contains are very lightweight layouter that allows the composition of strings in an easy and efficient way. However it can only handle string arguments and doesn't do any conversion.

import tango.text.Util;
void test1(){
  char[100] buffer = void;                                   // save the time for initialization (=void)
  char[] result = layout( buffer, "%1 is after %0", "zero", "one" );   // result is "one is after zero"
}

tango.text.convert.Format offers more power through conversions and formatting:

import tango.text.convert.Format;
void test1(){
  char[] result = Format.convert( buffer, "{1} is after {0}", 98, 99 );   // result is "99 is after 98"
}

Regular Expressions

Regular expressions lets you search for special patterns. You can retrieve parts of the match and do search replace actions.
Please see the module documentation tango.text.Regex.

Ascii and Unicode

The Ascii module offers functions for toLower(), toUpper(), compare(), icompare().
Please see the module documentation tango.text.Ascii

Note: Ascii is only the character value 0..127, everything above is something else. In D the char type is UTF8 which is different to eg. ISO-8859-1 (fequently confused with Ascii). If you need to convert from or to something else then Ascii, an external library is needed. E.g. see the mango project, there is a binding to the ICU lib, that can hanlde every encoding.

The tango.text.Unicode offers also test and conversion functions for single Unicode characters. E.g. toLower(), toUpper(), isSpace(), isPrintable(), ...
Please see the module documentation tango.text.Unicode

Note: to convert whole unicode string from one encoding into another (utf8/16/32) see Chapter Conversions - Utf

Store and manipulate Text

tango.text.Text

INI Files aka Properties

The Properties module has the static load() and save() functions, for loading Property files. This is a file format, where each line is of the format

# comment  
key = value

Please see the module documentation tango.io.stream.Map

import tango.io.stream.Map;
import tango.io.device.Array;

auto buf = new Array("name=tango\r\npath=D:\\tango");
char[][ char[] ] map;
auto input = new MapInput!(char)(buf);
input.load(map);

Given some text, a file, or a buffer, this will emit all lines contained:

source:/trunk/doc/images/LineIterator.gif

High level representation of a text string, with support for insert, remove, append, printf-style formatting, layout, utf conversion, custom comparison, etc. Also includes an immutable variant:

source:/trunk/doc/images/String.gif