class std::StrExt

sys::Obj
  std::StrExt

Str Extension

capitalize

static extension Str capitalize(Str self)

Return this string with the first character converted uppercase. The case conversion is for ASCII only. Also see decapitalize and localeCapitalize.

Example:

"foo".capitalize => "Foo"
decapitalize

static extension Str decapitalize(Str self)

Return this string with the first character converted lowercase. The case conversion is for ASCII only. Also see capitalize and localeDecapitalize.

Example:

"Foo".decapitalize => "foo"
extract

static extension Str? extract(Str str, Str? begin, Str? end)

get the sub string between begin and end

fromDisplayName

static extension Str fromDisplayName(Str self)

Translate a display name like "Foo Bar" to a programmatic name "fooBar". This method decapitalizes the first letter, then walks the string removing spaces. Also see toDisplayName.

Examples:

"Foo".fromDisplayName         ->  "foo"
"Foo Bar".fromDisplayName     ->  "fooBar"
"Foo Bar Baz".fromDisplayName ->  "fooBarBaz"
"Foo 33 Bar".fromDisplayName  ->  "foo33Bar"
"Foo XML".fromDisplayName     ->  "fooXML"
"foo bar".fromDisplayName     ->  "fooBar"
in

static extension InStream in(Str str)

Create an input stream to read characters from the this string. The input stream is designed only to read character data. Attempts to perform binary reads will throw UnsupportedErr.

justl

static extension Str justl(Str self, Int width)

If size is less than width, then add spaces to the right to create a left justified string. Also see padr.

Examples:

"xyz".justl(2) => "xyz"
"xyz".justl(4) => "xyz "
justr

static extension Str justr(Str self, Int width)

If size is less than width, then add spaces to the left to create a right justified string. Also see padl.

Examples:

"xyz".justr(2) => "xyz"
"xyz".justr(4) => " xyz"
numNewlines

static extension Int numNewlines(Str self)

Count the number of newline combinations: "\n", "\r", or "\r\n".

out

static extension OutStream out(StrBuf buf)

Create an output stream to append characters to this string buffer. The output stream is designed to write character data, attempts to do binary writes will throw UnsupportedErr.

padl

static extension Str padl(Str self, Int width, Int ch := 32)

If size is less than width, then add the given char to the left to achieve the specified width. Also see justr.

Examples:

"3".padl(3, '0') => "003"
"123".padl(2, '0') => "123"
padr

static extension Str padr(Str self, Int width, Int ch := 32)

If size is less than width, then add the given char to the left to acheive the specified with. Also see justl.

Examples:

"xyz".padr(2, '.') => "xyz"
"xyz".padr(5, '-') => "xyz--"
reverse

static extension Str reverse(Str self)

Reverse the contents of this string.

Example:

"stressed".reverse => "desserts"
splitAny

static extension List<Str> splitAny(Str str, Str sp, Bool normalize := true)

split by any char

splitBy

static extension List<Str> splitBy(Str str, Str sp, Int max := Int.maxVal)

split by Str

splitLines

static extension List<Str> splitLines(Str self)

Split this string into individual lines where lines are terminated by \n, \r\n, or \r. The returned strings do not contain the newline character.

Examples:

"x\ny".splitLines  => ["x", "y"]
"".splitLines      => [""]
"x".splitLines     => ["x"]
"\r\n".splitLines  => ["", ""]
"x\n".splitLines   => ["x", ""]
toBuf

static extension Buf toBuf(Str str, Charset charset := Charset.utf8)

Get this string encoded into a buffer of bytes.

toDisplayName

static extension Str toDisplayName(Str self)

Translate a programmer name like "fooBar" to "Foo Bar". This method capitalizes the first letter, then walks the string looking for ASCII capital letters and inserting a space. Any underbars are replaced with a space. Also see fromDisplayName.

Examples:

"foo".toDisplayName       ->  "Foo
"fooBar".toDisplayName    ->  "Foo Bar"
"fooBarBaz".toDisplayName ->  "Foo Bar Baz"
"foo33".toDisplayName     ->  "Foo 33"
"fooXML".toDisplayName    ->  "Foo XML"
"Foo".toDisplayName       ->  "Foo"
"foo_bar".toDisplayName   ->  "Foo Bar"