class Strings
package thx
Extension methods for strings.
Static variables
Static methods
staticafter (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.
staticafterLast (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.
staticinline capitalize (s:String):String
capitalize
returns a string with the first character convert to upper case.
staticcapitalizeWords (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.
staticinline caseInsensitiveContains (s:String, test:String):Bool
contains
returns true
if s
contains one or more occurrences of test
regardless of the text case.
staticinline caseInsensitiveContainsAll (s:String, tests:Array<String>):Bool
contains
returns true
if s
contains all of the strings in tests
regardless of the text case
staticinline caseInsensitiveContainsAny (s:String, tests:Array<String>):Bool
contains
returns true
if s
contains any of the strings in tests
regardless of the text case
staticinline caseInsensitiveEndsWith (s:String, end:String):Bool
Returns true if s
ends with end
ignoring their case.
staticinline 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.
staticinline caseInsensitiveStartsWith (s:String, start:String):Bool
Compares two strings ignoring their case.
staticinline 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.
staticcollapse (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
.
staticinline 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.
staticinline contains (s:String, test:String):Bool
contains
returns true
if s
contains one or more occurrences of test
.
staticinline containsAll (s:String, tests:Array<String>):Bool
contains
returns true
if s
contains all of the strings in tests
staticinline containsAny (s:String, tests:Array<String>):Bool
contains
returns true
if s
contains any of the strings in tests
staticdiffAt (a:String, b:String):Int
Compares strings a
and b
and returns the position where they differ.
Strings.diffAt("abcdef", "abc123"); // returns 3
staticellipsis (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 …'
staticellipsisMiddle (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'
staticendsWithAny (s:String, values:Iterable<String>):Bool
Returns true
if s
ends with any of the values in values
.
staticfilter (s:String, predicate:String ‑> Bool):String
filter
applies predicate
character by character to s
and it returns a filtered
version of the string.
staticfilterCharcode (s:String, predicate:Int ‑> Bool):String
Same as filter
but predicate
operates on integer char codes instead of string characters.
staticfrom (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.
staticinline hasContent (value:String):Bool
Returns true
if value
is not null
and contains at least one character.
statichumanize (s:String):String
Works the same as underscore
but also replaces underscores with whitespaces.
staticinline ifEmpty (value:String, alt:String):String
ifEmpty
returns value
if it is neither null
or empty, otherwise it returns alt
staticinline isAlphaNum (value:String):Bool
isAlphaNum
returns true
if the string only contains alpha-numeric characters.
staticinline isDigitsOnly (value:String):Bool
isDigitsOnly
returns true
if the string only contains digits.
staticisEmpty (value:String):Bool
isEmpty
returns true if either value
is null or is an empty string.
staticisLowerCase (value:String):Bool
Returns true
if the value string is composed of only lower cased characters
or case neutral characters.
staticisUpperCase (value:String):Bool
Returns true
if the value string is composed of only upper cased characters
or case neutral characters.
staticiterator (s:String):Iterator<String>
It returns an iterator holding in sequence one character of the string per iteration.
staticmap<T> (value:String, callback:String ‑> T):Array<T>
It maps a string character by character using callback
.
staticrandom (value:String, length:Int = 1):String
Returns a random substring from the value
argument. The length of such value is by default 1
.
staticrandomSequence (seed:String, length:Int):String
Returns a random sampling of the specified length from the seed string.
staticrandomSequence64 (length:Int):String
Like Strings.randomSequence
, but automatically uses haxe.crypto.Base64.CHARS
as the seed string.
staticinline remove (value:String, toremove:String):String
If present, it removes all the occurrences of toremove
from value
.
staticremoveAfter (value:String, toremove:String):String
If present, it removes the toremove
text from the end of value
.
staticremoveAt (value:String, index:Int, length:Int):String
Removes a slice from index
to index + length
from value
.
staticremoveBefore (value:String, toremove:String):String
If present, it removes the toremove
text from the beginning of value
.
staticremoveOne (value:String, toremove:String):String
If present, it removes the first occurrence of toremove
from value
.
staticrepeat (s:String, times:Int):String
repeat
builds a new string by repeating the argument s
, n times
.
'Xy'.repeat(3); // generates 'XyXyXy'
staticsplitOnce (s:String, separator:String):Array<String>
Like StringTools.split
but it only splits on the first occurrance of separator.
staticstartsWithAny (s:String, values:Iterable<String>):Bool
Returns true
if s
starts with any of the values in values
.
staticstripTags (s:String):String
stripTags
removes any HTML/XML markup from the string leaving only the concatenation
of the existing text nodes.
staticinline 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;
staticinline toCharcodes (s:String):Array<Int>
It transforms a string into an Array
of char codes in integer format.
statictoChunks (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.
staticinline trimChars (value:String, charlist:String):String
trimChars
removes from the beginning and the end of the string any character that is present in charlist
.
statictrimCharsLeft (value:String, charlist:String):String
trimCharsLeft
removes from the beginning of the string any character that is present in charlist
.
statictrimCharsRight (value:String, charlist:String):String
trimCharsRight
removes from the end of the string any character that is present in charlist
.
staticunderscore (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.
staticupTo (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.
staticwrapColumns (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.