View source

class thx.Strings

Available on all platforms

Extension methods for strings.

Class Fields

static var monoid(default,null):Monoid<String>

static var ord(default,null):Ord<String>

static function after(value:String, searchFor:String):String

after searches for the first occurrance of searchFor and returns the text after that.

If searchFor is not found, an empty string is returned.

static function afterLast(value:String, searchFor:String):String

afterLast searches for the last occurrance of searchFor and returns the text after that.

If searchFor is not found, an empty string is returned.

static function canonicalizeNewlines(value:String):String

Replaces occurrances of \r\n, \n\r, \r with \n;

static inline function capitalize(s:String):String

capitalize returns a string with the first character convert to upper case.

static function capitalizeWords(value:String, whiteSpaceOnly:Bool = false):String

Capitalize the first letter of every word in value. If whiteSpaceOnly is set to true the process is limited to whitespace separated words.

static inline function caseInsensitiveCompare(a:String, b:String):Int

Compares two strings ignoring their case.

static inline function caseInsensitiveEndsWith(s:String, end:String):Bool

Returns true if s ends with end ignoring their case.

static inline function caseInsensitiveEndsWithAny(s:String, values:Array<String>):Bool

Compares a string s with many values and see if one of them matches its end ignoring their case.

static inline function caseInsensitiveStartsWith(s:String, start:String):Bool

Compares two strings ignoring their case.

static inline function caseInsensitiveStartsWithAny(s:String, values:Array<String>):Bool

Compares a string s with many values and see if one of them matches its beginning ignoring their case.

static function collapse(value:String):String

It cleans up all the whitespaces in the passed value. collapse does the following:

  • remove trailing/leading whitespaces
  • within the string, it collapses seqeunces of whitespaces into a single space character

For whitespaces in this description, it is intended to be anything that is matched by the regular expression \s.

static inline function compare(a:String, b:String):Int

It compares to string and it returns a negative number if a is inferior to b, zero if they are the same, or otherwise a positive non-sero number.

static inline function contains(s:String, test:String):Bool

contains returns true if s contains one or more occurrences of test.

static inline function containsAny(s:String, tests:Array<String>):Bool

contains returns true if s contains any of the strings in tests

static function count(s:String, test:String):Int

Return the number of occurances of test in s.

static function dasherize(s:String):String

dasherize replaces all the occurrances of _ with -;

static function diffAt(a:String, b:String):Int

Compares strings a and b and returns the position where they differ.

Strings.diffAt("abcdef", "abc123"); // returns 3

static function ellipsis(s:String, maxlen:Int = 20, symbol:String = "…"):String

ellipsis truncates s at len maxlen replaces the last characters with the content of symbol.

'thx is a nice library'.ellipsis(8); // returns 'thx is …'

static function ellipsisMiddle(s:String, maxlen:Int = 20, symbol:String = "…"):String

Same as ellipsis but puts the symbol in the middle of the string and not to the end.

'thx is a nice library'.ellipsisMiddle(16); // returns 'thx is … library'

static function endsWithAny(s:String, values:Iterable<String>):Bool

Returns true if s ends with any of the values in values.

static function filter(s:String, predicate:String -> Bool):String

filter applies predicate character by character to s and it returns a filtered version of the string.

static function filterCharcode(s:String, predicate:Int -> Bool):String

Same as filter but predicate operates on integer char codes instead of string characters.

static function from(value:String, searchFor:String):String

from searches for the first occurrance of searchFor and returns the text from that point on.

If searchFor is not found, an empty string is returned.

static inline function hasContent(value:String):Bool

Returns true if value is not null and contains at least one character.

static function hashCode(value:String):Int

static function humanize(s:String):String

Works the same as underscore but also replaces underscores with whitespaces.

static inline function ifEmpty(value:String, alt:String):String

ifEmpty returns value if it is neither null or empty, otherwise it returns alt

static function isAlpha(s:String):Bool

Checks if s contains only (and at least one) alphabetical characters.

static inline function isAlphaNum(value:String):Bool

isAlphaNum returns true if the string only contains alpha-numeric characters.

static function isBreakingWhitespace(value:String):Bool

static inline function isDigitsOnly(value:String):Bool

isDigitsOnly returns true if the string only contains digits.

static function isEmpty(value:String):Bool

isEmpty returns true if either value is null or is an empty string.

static function isLowerCase(value:String):Bool

Returns true if the value string is composed of only lower cased characters or case neutral characters.

static function isUpperCase(value:String):Bool

Returns true if the value string is composed of only upper cased characters or case neutral characters.

static function iterator(s:String):Iterator<String>

It returns an iterator holding in sequence one character of the string per iteration.

static function lowerCaseFirst(value:String):String

Convert first letter in value to lower case.

static function lpad(s:String, char:String, length:Int):String

static function map<T>(value:String, callback:String -> T):Array<T>

It maps a string character by character using callback.

static function quote(s:String):String

Converts a string in a quoted string.

static function random(value:String, length:Int = 1):String

Returns a random substring from the value argument. The length of such value is by default 1.

static function randomSequence(seed:String, length:Int):String

Returns a random sampling of the specified length from the seed string.

static function randomSequence64(length:Int):String

Like Strings.randomSequence, but automatically uses haxe.crypto.Base64.CHARS as the seed string.

static inline function remove(value:String, toremove:String):String

If present, it removes all the occurrences of toremove from value.

static function removeAfter(value:String, toremove:String):String

If present, it removes the toremove text from the end of value.

static function removeAt(value:String, index:Int, length:Int):String

Removes a slice from index to index + length from value.

static function removeBefore(value:String, toremove:String):String

If present, it removes the toremove text from the beginning of value.

static function removeOne(value:String, toremove:String):String

If present, it removes the first occurrence of toremove from value.

static function repeat(s:String, times:Int):String

repeat builds a new string by repeating the argument s, n times.

'Xy'.repeat(3); // generates 'XyXyXy'

static function reverse(s:String):String

Returns a new string whose characters are in reverse order.

static function rpad(s:String, char:String, length:Int):String

static function splitOnce(s:String, separator:String):Array<String>

Like StringTools.split but it only splits on the first occurrance of separator.

static function startsWithAny(s:String, values:Iterable<String>):Bool

Returns true if s starts with any of the values in values.

static function stripTags(s:String):String

stripTags removes any HTML/XML markup from the string leaving only the concatenation of the existing text nodes.

static inline function surround(s:String, left:String, ?right:String):String

Surrounds a string with the contents of left and right. If right is omitted, left will be used on both sides;

static function toArray(s:String):Array<String>

It transforms a string into an Array of characters.

static inline function toCharcodes(s:String):Array<Int>

It transforms a string into an Array of char codes in integer format.

static function toChunks(s:String, len:Int):Array<String>

Returns an array of String whose elements are equally long (using len). If the string s is not exactly divisible by len the last element of the array will be shorter.

static inline function toLines(s:String):Array<String>

Returns an array of String split by line breaks.

static inline function trimChars(value:String, charlist:String):String

trimChars removes from the beginning and the end of the string any character that is present in charlist.

static function trimCharsLeft(value:String, charlist:String):String

trimCharsLeft removes from the beginning of the string any character that is present in charlist.

static function trimCharsRight(value:String, charlist:String):String

trimCharsRight removes from the end of the string any character that is present in charlist.

static function underscore(s:String):String

underscore finds UpperCase characters and turns them into LowerCase and prepends them with a whtiespace. Sequences of more than one UpperCase character are left untouched.

static function upTo(value:String, searchFor:String):String

upTo searches for the first occurrance of searchFor and returns the text up to that point.

If searchFor is not found, the entire string is returned.

static function upperCaseFirst(value:String):String

Convert first letter in value to upper case.

static function wrapColumns(s:String, columns:Int = 78, indent:String = "", newline:String = "\n"):String

wrapColumns splits a long string into lines that are at most columns long.

Words whose length exceeds columns are not split.

Toggle inherited fields