String functions

Functions to read and manipulate string variables.

gui­d

Creates a new random GUID as 36 lower-case characters with hyphens, for example 3f2504e0-4f89-41d3-9a0c-0305e82c3301. Available as guid()…

guid­2

Creates a new random GUID in a short, URL-safe Base64 format: 22 characters from A–Z, a–z, 0–9, - and _. Only available as docly.guid2().

md­5(text)

Returns the MD5 hash of the text as 32 upper-case hexadecimal characters. The text is encoded as UTF-8, numbers are converted the…

sha25­6(text)

Returns the SHA-256 hash of the text as 64 upper-case hexadecimal characters. The text is encoded as UTF-8, numbers are converted the…

Temp­late li­teral (temp­lat­e st­rings­)

Template literals are strings that can cross multiple lines and easily bind in values through single JS expressions inside the string. The…

text­Deco­d­e(bytes, encoding)

Converts a byte array to a string using the specified encoding.

tex­tEn­cod­e(text, encoding)

Converts a string into bytes using the specified encoding.

toHtm­l(text, text2, ...)

Converts multi-line plain text to HTML: encodes HTML characters (like htmlEncode), turns line breaks into <br /> and URLs into links. Line…

en­code­Fil­ena­me(filename)

Encode a filename by replacing characters not allowed in filenames with their ASCII code representations. Reverse function of…

de­code­Fil­ena­me(filename)

Decode an encoded filename string by replacing ASCII code representations with symbols (not allowed in filenames). Reverse function of…

en­codeU­RI(text)

Encodes a URI by replacing certain characters by escape sequences representing the UTF-8 encoding of the characters.

en­codeU­RI­Com­ponen­t(text)

Encodes a URI component by replacing certain characters with escape sequences representing the UTF-8 encoding. Unlike encodeURI, it also…

htm­lAtt­ri­bu­teEn­cod­e(text)

The HtmlAttributeEncode method encodes characters appropriate for insertion into an HTML attribute value.

htm­lEn­cod­e(text)

Encodes <, >, &, " and ' as HTML entities, so text can be placed safely in HTML element content. Several arguments are encoded and joined.…

re­moveEm­pty­Line­s(text)

Removes empty lines, and lines that contain only white space, from a string.

St­ring.­co­nca­t(string1, string2, ...)

Returns this string joined with the arguments. The input strings are not changed. Values are converted with .NET formatting, so true…

St­ring­.in­clu­des(search)

The includes() method returns true if a string contains a specified string.

St­ring.­su­bst­rin­g(start, end)

The substring() method returns a part of the string between the start and end indexes, or to the end of the string.

St­ring­.in­d­exO­f(text, position)

Searches the entire calling string, and returns the index of the first occurrence of the specified substring.

St­ring.­la­stIn­dexO­f(text, position)

Searches for the last occurrence of a substring within a string.

St­ring.­no­rma­lize(form)

Returns the Unicode Normalization Form of the string, allowing comparison of strings that may use different code-point sequences for the…

St­ring.­re­pea­t(times)

Repeats a string a specified number times and returns the new value.

St­ring.­re­pla­ce(find, replace)

Returns a new string where the FIRST occurrence of find is replaced. To replace every occurrence, use replaceAll() or a regular expression…

St­ring.s­pli­t(separator, limit)

Splits a single string into an array of strings based on the specified separator. In template mode there is also an older global helper…

St­ring­.en­ds­Wit­h(text)

Searches the end of the string, and returns a boolean that is True if the string ends with this text otherwise False.

St­ring.s­t­arts­Wit­h(text)

Searches the start of the string, and returns a boolean that is True if the string starts with this text otherwise False.

St­ring.t­r­im

Removes white space — spaces, tabs and line breaks — from both ends of a string. trimStart() and trimEnd() remove it from one end only.…

st­rip­Tag­s(html)

Removes all tags from a string

ur­lEn­code(text)

URL-encodes text the way HTML forms do: a space becomes + and other unsafe characters become %xx. Use encodeURIComponent() when you need…

mark­dow­n(text)

Converts Markdown-formatted text to HTML.

St­ring.s­l­ice(start, end)

Returns the part of the string from start up to (not including) end. Negative values count from the end of the string. Unlike substring(),…

St­ring.­pa­dS­tar­t(targetLength, padString)

Pads the start of the string with another string until it reaches the given length — typically for leading zeros. padEnd() pads at the end…

St­ring.­re­pla­ceAl­l(pattern, replacement)

Returns a new string where every occurrence of the search text is replaced. The original string is not changed. With a regular expression,…

St­ring.­ma­tc­h(pattern)

Searches the string with a regular expression. If you pass text instead of a regular expression, HashJS searches for that exact text —…

St­ring.­to­Lo­wer­Case

Returns the string converted to lower case. Letters such as Æ, Ø and Å are converted too. toLocaleLowerCase() gives the same result.

St­ring.­to­Up­per­Case

Returns the string converted to upper case. Letters such as æ, ø and å are converted too. toLocaleUpperCase() gives the same result.