View source code
Display the source code in std/string.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone.

Function std.string.column

Compute column number at the end of the printed form of the string, assuming the string starts in the leftmost column, which is numbered starting from 0.

size_t column(Range) (
  Range str,
  in size_t tabsize = 8
)
if ((isInputRange!Range && isSomeChar!(ElementEncodingType!Range) || isNarrowString!Range) && !isConvertibleToString!Range);

Tab characters are expanded into enough spaces to bring the column number to the next multiple of tabsize. If there are multiple lines in the string, the column number of the last line is returned.

Parameters

NameDescription
str string or InputRange to be analyzed
tabsize number of columns a tab character represents

Returns

column number

Example

import std.utf : byChar, byWchar, byDchar;

writeln(column("1234 ")); // 5
writeln(column("1234 "w)); // 5
writeln(column("1234 "d)); // 5

writeln(column("1234 ".byChar())); // 5
writeln(column("1234 "w.byWchar())); // 5
writeln(column("1234 "d.byDchar())); // 5

// Tab stops are set at 8 spaces by default; tab characters insert enough
// spaces to bring the column position to the next multiple of 8.
writeln(column("\t")); // 8
writeln(column("1\t")); // 8
writeln(column("\t1")); // 9
writeln(column("123\t")); // 8

// Other tab widths are possible by specifying it explicitly:
writeln(column("\t", 4)); // 4
writeln(column("1\t", 4)); // 4
writeln(column("\t1", 4)); // 5
writeln(column("123\t", 4)); // 4

// New lines reset the column number.
writeln(column("abc\n")); // 0
writeln(column("abc\n1")); // 1
writeln(column("abcdefg\r1234")); // 4
writeln(column("abc\u20281")); // 1
writeln(column("abc\u20291")); // 1
writeln(column("abc\u00851")); // 1
writeln(column("abc\u00861")); // 5

Authors

Walter Bright, Andrei Alexandrescu, Jonathan M Davis, and David L. 'SpottedTiger' Davis

License

Boost License 1.0.