String

Additional functions on the JS String object

Summary
StringAdditional functions on the JS String object
Properties
htmlEscapeCharsStatic Array of characters to be translated by escapeHtml and unEscapeHtml
Functions
afterreturns all the characters after the first count characters
beforereturns all the characters before the last count characters
charToHtmlEntityreturns the HTML/XML entity of the supplied character in &#code; format where code is the decimal ASCII code
compareAlphaStatic A static sort function that will compare two strings by lexigraphical order.
compareAlphaNoCaseStatic A case-insensitive version of String.compareAlpha
compareAlphaReverseStatic A descending version of compareAlpha.
compareAlphaReverseNoCaseStatic A case-insensitive version of String.compareAlphaReverse
compareNaturalStatic A static sort function that will compare two strings in a natural way.
compareNaturalNoCaseStatic A case-insensitive version of String.compareNatural
compareNaturalReverseStatic A descending version of compareNatural.
compareNaturalReverseNoCaseStatic A case-insensitive version of String.compareNaturalReverse
compareNumericStatic A static sort function that will compare two strings by lexigraphical order.
compareNumericReverseStatic A descending version of compareNumeric.
endsWithreturns true if this string ends with supplied string
escapeHtmlreplaces common symbols with their HTML entity equivalents
escapeRegexreturns string with symbols that might be interpreted as regex escaped
escapeJsreturns string with symbols that might be interpreted as JavaScript escaped
formatreturns a string with parameters replaced
getLineIteratorreturns java Iterator that produces a line at a time for this string
htmlEntityToCharStatic returns the chatacter representation of the supplied HTML/XML entity
leftreturns the left side of a string
lpadpads the left side of this string
listAppendreturns new list (string) with value appended (does not modify original string).
listAppendUniquereturns new list (string) with value appended, if not already in list
listAppendUniqueNoCasereturns new list (string) with value appended, if not already in list, ignoring case
listAfterreturns this list minus the first element.
listBeforereturns this list minus the last element.
listContainsreturns true if list contains the value.
listContainsNoCasereturns true if list contains the value, ignoring case.
listFindreturns the index of a value in a list
listFindNoCasereturns the index of a value in a list, ignoring case
listFirstreturns the first value of a list.
listLastreturns the last value of a list.
listAtreturns the list value at a specific location, or “”.
listLenreturns the length of a list
listGetUniquereturns new list (string) with each item represented only once
listMakeUniqueNoCasereturns new list (string) with each item represented only once, regardless of case.
listQualifyreturns new list (string) with each item surrounded by a qualifying symbol
listSamereturns true if the provided list contains the smae elements as this list regardless of order.
listSameNoCasereturns true if the provided list contains the smae elements as this list regardless of order.
listSortreturns a copy of this list sorted by the supplied sort function
listToArrayreturns an array of the items in this list
toFixedWidthreturns this string padded/truncated to the specified length
parseJsonConverts a JSON (http://www.json.org) string into an object
rightreturns the right side of a string
repeatreturns a copy of this string repeated count times
rpadpads the right side of this string
splitCapreturns an array of the “words” in this string as delimited by Capital letters
startsWithreturns true if this string starts with supplied string
titleCapCapitalizes the first letter of every word in string
trimreturns a new string with beginning and trailing whitespace removed
trimIndentreturns a new string with the initial white space on each line trimmed
unEscapeHtmlreverses the replacements in escapeHtml
checksumreturns a simple String checksum(digest) for this string.
hashCodereturns java.lang.String.hasCode() for this string
hashEqualsReturns true if the plaintext password matches the encrypted password
toHashReturns a copy of this string encrypted with a strong one-way hash in base64 format.
decryptReturns the unencrypted string contained in this string
encryptEncrypts this string using a password.
pipealias for Myna.exec, using this contents of this string as the options.input
toJavareturns a new java.lang.String of this string
toXmlreturns an E4X XML object from this string, or throws an exception if not possible
toXmlDocreturns an org.w3c.dom.Document object from this string, or throws an exception if not possible
escapeUrlreturns a URL encoded version of this string

Properties

htmlEscapeChars

Static Array of characters to be translated by escapeHtml and unEscapeHtml

Functions

after

String.prototype.after=function(count,
caseSensitive)

returns all the characters after the first count characters

Parameters

countnumber of characters to skip, a string or a RegExp object
caseSensitiveOptional, default false if count is a string, should the match be case sensitive?

Returns

string that appears after count, or “” if not possible

Example

var string = "JoeBlow"
Myna.println(string.after(3));//prints Blow
Myna.println(string.after(/e/,true));//prints Blow
Myna.println(string.after(/^joe/i,true));//prints Blow
Myna.println(string.after("joe"));//prints Blow
Myna.println(string.after("joe",true));//prints null because we forced case sensitivity

var requestDir = $server.requestDir;

// this is an example only. $server.requestUrl does this for you
var requestUrl = requestDir.after($server.rootDir);

before

String.prototype.before=function(count)

returns all the characters before the last count characters

Parameters

countnumber of characters to remove from the end of this string, a string, or a RegExp object
caseSensitiveOptional, default false if count is a string, should the match be case sensitive?

Returns

string that appears before count, or “” if not possible

Example

var string = "JoeBlow"
Myna.println(string.before(4));//prints Joe
Myna.println(string.before(/o/,true));//prints J
Myna.println(string.before(/o$/,true));//prints JoeBl
Myna.println(string.before(/blow/i,true));//prints Joe
Myna.println(string.before("blow"));//prints Joe
Myna.println(string.before("blow",true));//prints null because we forced case sensitivity


var requestUrl = $server.requestUrl;
var contextRelativeUrl = requestUrl.after($server.rootUrl);

// this is an example only. $server.rootDir does this for you
var rootDir = $server.requestDir.before(contextRelativeUrl);

charToHtmlEntity

String.charToHtmlEntity = function(c)

returns the HTML/XML entity of the supplied character in &#code; format where code is the decimal ASCII code

Parameters

c1 character string to convert

compareAlpha

String.compareAlpha = function(a,
b)

Static A static sort function that will compare two strings by lexigraphical order.

Paramters

afirst string to compare
bsecond string to compare

Returns

-1if a > b
0if a == b
1if a < b

compareAlphaNoCase

String.compareAlphaNoCase = function(a,
b)

Static A case-insensitive version of String.compareAlpha

compareAlphaReverse

String.compareAlphaReverse = function(a,
b)

Static A descending version of compareAlpha.

Paramters

afirst string to compare
bsecond string to compare

Returns

-1if a < b
0if a == b
1if a > b

see compareAlpha

compareAlphaReverseNoCase

String.compareAlphaReverseNoCase = function(a,
b)

Static A case-insensitive version of String.compareAlphaReverse

compareNatural

String.compareNatural = function(a,
b)

Static A static sort function that will compare two strings in a natural way.

Paramters

afirst string to compare
bsecond string to compare

Returns

-1if a > b
0if a == b
1if a < b

Detail

The standard sort function does ASCII comparisons of the entire string.  Humans tend to sort based on parts of the string, applying numeric and alpha sorts as appropriate, and ignoring case.  Take this list:

var stringArray="A8,a10,A11,a14c,a14b9,a14B10,A14B10,a14b10,a9".split(/,/);

Calling stringArray.sort() will result in

A11
A14B10
A8
a10
a14B10
a14b10
a14b9
a14c
a9

This is a valid ASCII sort, but doesn’t look “right” to humans.  Calling stringArray.sort(String.compareNatural) will result in

A8
a9
a10
A11
a14b9
A14B10
a14B10
a14b10
a14c

compareNaturalNoCase

String.compareNaturalNoCase = function(a,
b)

Static A case-insensitive version of String.compareNatural

compareNaturalReverse

String.compareNaturalReverse = function(a,
b)

Static A descending version of compareNatural.

Paramters

afirst string to compare
bsecond string to compare

Returns

-1if a < b
0if a == b
1if a > b

see compareNatural

compareNaturalReverseNoCase

String.compareNaturalReverseNoCase = function(a,
b)

Static A case-insensitive version of String.compareNaturalReverse

compareNumeric

String.compareNumeric = function(a,
b)

Static A static sort function that will compare two strings by lexigraphical order.

Paramters

afirst string to compare
bsecond string to compare

Returns

-1if a > b
0if a == b
1if a < b

compareNumericReverse

String.compareNumericReverse = function(a,
b)

Static A descending version of compareNumeric.

Paramters

afirst string to compare
bsecond string to compare

Returns

-1if a < b
0if a == b
1if a > b

see compareNumeric

endsWith

String.prototype.endsWith = function(str,
caseSensitive)

returns true if this string ends with supplied string

Parameters

strstring to match
caseSensitiveOptional, default false Should the match be case sensitive?

See Also

Example

Myna.println(“BobDobb”.endsWith(“dobb”))//prints true Myna.println(“BobDobb”.endsWith(“dobb”,true))//prints false

escapeHtml

String.prototype.escapeHtml=function(string)

replaces common symbols with their HTML entity equivalents

Detail

the purpose of this function is to prevent a string from being interpreted as HTML/JavaScript when output on a webpage.

Returns

converted string

Detail

escapes the following symbols:

;   becomes &#59;
& becomes &#38;
# becomes &#35;
< becomes &#60;
> becomes &#62;
' becomes &#39;
" becomes &#34;
( becomes &#40;
) becomes &#41;
% becomes &#37;
+ becomes &#43;
- becomes &#45;

See: $req.data,<$req.rawData>,<unEscapeHtml>

escapeRegex

String.prototype.escapeRegex=function(string)

returns string with symbols that might be interpreted as regex escaped

Detail

the purpose of this function is to prevent a string from being interpreted as a regex string when using new RegExp

Returns

converted string

escapeJs

String.prototype.escapeJs=function()

returns string with symbols that might be interpreted as JavaScript escaped

Detail

the purpose of this function is to prevent a string from being interpreted as JavaScript when used as a string literal in a JS expression

Returns

converted string

Example

//index.ejs

<script>
var postTitle = "<%=Post.title.escapeJs()%>";
</script>

format

String.prototype.format=function(values)

returns a string with parameters replaced

Parameters

values...Either multiple value parameters, a single parameter array or a JS object containing key/value pairs

Detail

This provides a very simple templating system for strings.  Bracketed terms (e.g.{1} or {paramName}) in this string are replaced with that matching index in values.  For parameter list or a single parameter array, positional terms ({0},{1},...{n}) are replaced.  For a single object parameter, matching property names are replaced ({age},{height},{DOB})

Returns

converted string

Example

var saying = "This is the {0} of our {1}. words:{0},{1}".format("summer","discontent")
var saying2 = "This is the {season} of our {feeling}. words:{season},{feeling}".format({
season:"summer",
feeling:"discontent"
})

getLineIterator

String.prototype.getLineIterator = function()

returns java Iterator that produces a line at a time for this string

Detail

If you are working with large strings, split().forEach() may be inefficient.  This function produces a Java Iterator object that can be used to efficiently loop over all the lines in this string.

Example

//big text chunk
var text = qry.data[0].big_text_field;
for (var line in text.getLineIterator()){
... do stuff with line...
}

See Also

Myna.File.getLineIterator

htmlEntityToChar

String.htmlEntityToChar = function(e)

Static returns the chatacter representation of the supplied HTML/XML entity

Parameters

eHTML/XML entity in &#code; format where code is the decimal ASCII code

left

String.prototype.left=function(count)

returns the left side of a string

Parameters

countnumber of characters to return

Returns

The left count characters of string

lpad

String.prototype.lpad=function(count,
padChar)

pads the left side of this string

Parameters

counttotal length after padding
padCharcharacter to pad with

Returns

padded string

Note

this is is an alias for <toFixedWidth>(count,_padChar_,null,”start”)

listAppend

String.prototype.listAppend=function(val,
delimiter,
qualifier)

returns new list (string) with value appended (does not modify original string).

Parameters

valString value to append
delimiterOptional, default “,” String delimiter to append to this string before val.  If this string is empty, or currently ends with delimiter, delimiter will not be appended. returned string
qualifierOptional, default null String to put before and after val

Returns

A new list with val appended.

listAppendUnique

String.prototype.listAppendUnique=function(val,
delimiter,
qualifier)

returns new list (string) with value appended, if not already in list

Parameters

valString value to append
delimiterOptional, default “,” String delimiter to append to this string before val.  If this string is empty, or currently ends with delimiter, delimiter will not be appended. returned string
qualifierOptional, default null String to put before and after val

Returns

A new list with val appended.

listAppendUniqueNoCase

String.prototype.listAppendUniqueNoCase=function(val,
delimiter,
qualifier)

returns new list (string) with value appended, if not already in list, ignoring case

Parameters

valString value to append
delimiterOptional, default “,” String delimiter to append to this string before val.  If this string is empty, or currently ends with delimiter, delimiter will not be appended. returned string
qualifierOptional, default null String to put before and after val

listAfter

String.prototype.listAfter=function(delimiter,
qualifier)

returns this list minus the first element.

Parameters

delimiterOptional default ‘,’ String delimiter between values
qualifierOptional, default null String that is on both sides of values in the string

listBefore

String.prototype.listBefore=function(delimiter)

returns this list minus the last element.

Parameters

delimiterOptional default ‘,’ String delimiter between values

listContains

String.prototype.listContains=function(val,
delimiter,
qualifier)

returns true if list contains the value.

Parameters

valString Value to search for.  If val is a list with the same delimiter then all values in val must also be in this string
delimiterOptional default ‘,’ String delimiter between values
qualifierOptional, default null String found before and after val Returns: true if val exists in this string

listContainsNoCase

String.prototype.listContainsNoCase=function(val,
delimiter,
qualifier)

returns true if list contains the value, ignoring case.

Parameters

valString Value to search for.  If val is a list with the same delimiter then all values in val must also be in this string
delimiterOptional default ‘,’ String delimiter between values
qualifierOptional, default null String that is on both sides of values in the string

Returns

true if val exists in list

listFind

String.prototype.listFind=function(val,
startFrom,
delimiter,
qualifier)

returns the index of a value in a list

Parameters

valString value to search for
startFromOptional default 0 Index to start looking for a match
delimiterOptional default ‘,’ String delimiter between values
qualifierOptional, default null String that is on both sides of values in the string

Returns

index of first found match, or -1 if no match

listFindNoCase

String.prototype.listFindNoCase=function(val,
startFrom,
delimiter,
qualifier)

returns the index of a value in a list, ignoring case

Parameters

valString value to search for
startFromOptional default 0 Index to start looking for a match
delimiterOptional default ‘,’ String delimiter between values
qualifierOptional, default null String that is on both sides of values in the string

Returns

index of first found match, or -1 if no match

listFirst

String.prototype.listFirst=function(delimiter,
qualifier)

returns the first value of a list.

Parameters

delimiterOptional default ‘,’ String delimiter between values
qualifierOptional, default null String that is on both sides of values in the string

Returns

the first value of list

listLast

String.prototype.listLast=function(delimiter,
qualifier)

returns the last value of a list.

Parameters

delimiterOptional default ‘,’ String delimiter between values
qualifierOptional, default null String that is on both sides of values in the string Returns: the last value of list

listAt

String.prototype.listAt=function(position,
delimiter,
qualifier)

returns the list value at a specific location, or “”.

Parameters

position0-based position
delimiterOptional default ‘,’ String delimiter between values
qualifierOptional, default null String that is on both sides of values in the string

listLen

String.prototype.listLen=function(delimiter)

returns the length of a list

Parameters

delimiterOptional default ‘,’ String delimiter between values

Returns

number of values in this string

listGetUnique

String.prototype.listMakeUnique=String.prototype.listGetUnique=function(
   delimiter
)

returns new list (string) with each item represented only once

Parameters

delimiterOptional, default “,” String delimiter to append to this string before val.  If this string is empty, or currently ends with delimiter, delimiter will not be appended. returned string

listMakeUniqueNoCase

String.prototype.listMakeUniqueNoCase=function(delimiter)

returns new list (string) with each item represented only once, regardless of case.  If an item appears more than once in different upper/lower case, only the first occurance is kept.

Parameters

delimiterOptional, default “,” String delimiter to append to this string before val.  If this string is empty, or currently ends with delimiter, delimiter will not be appended.

listQualify

String.prototype.listQualify=function(symbol,
delimiter,
qualifier)

returns new list (string) with each item surrounded by a qualifying symbol

Parameters

symbolOptional, default ‘ (single quote)
delimiterOptional, default “,” The delimiter for this list
qualifierOptional, default null Current qualifier for this list

listSame

String.prototype.listSame=function(list,
delimiter)

returns true if the provided list contains the smae elements as this list regardless of order.  Both lists must use the same qualifier and delimiter

Parameters

listlist to compare to this one
delimiterOptional default ‘,’ String delimiter between values

listSameNoCase

String.prototype.listSameNoCase=function(list,
delimiter)

returns true if the provided list contains the smae elements as this list regardless of order.  Both lists must use the same qualifier and delimiter

Parameters

listlist to compare to this one
delimiterOptional default ‘,’ String delimiter between values

listSort

String.prototype.listSort=function(sortFunc,
delimiter,
qualifier)

returns a copy of this list sorted by the supplied sort function

Parameters

sortFunOptional, default String.compareAlpha A function that takes two strings and returns -1, 0, or 1.  If null the default Array sort is used.  This function will be passed to Array.sort().  The String.compare* functions are easy plugins for this
delimiterOptional default ‘,’ String delimiter between values
qualifierOptional, default null String remove from both sides of each item

Detail

This function converts the string list into an array of string items, sorts the array with sortFunc, and returns the array converted back into a string list.

See

listToArray

String.prototype.listToArray=function(delimiter,
qualifier)

returns an array of the items in this list

Parameters

delimiterOptional default ‘,’ String delimiter between values
qualifierOptional, default null String remove from both sides of each item

toFixedWidth

String.prototype.toFixedWidth=function(count,
pad,
placeHolder,
truncateFrom)

returns this string padded/truncated to the specified length

Parameters

countnumber of characters to return.  If this is 0 or negative an empty string will be returned
padOptional, default “ “ Character to add to the right side of the string to pad to the fixed width
placeHolderOptional, default undefined If defined, this string will be used as the placeholder for text removed to make the string fit the the fixed length.  The length of this string is subtracted from count so that the resulting string will not exceed count
truncateFromOpitional, default “end” This sets where the placholder will be placed in the string and from where characters will be removed.  Valid values are “start”, “middle” and “end”

Returns

returns a string forced to count length, truncating or padding as necessary

Example

var delim = " | ";
var str = "Description".toFixedWidth(15) + delim + "Price".toFixedWidth(5) + "\n";
data.forEach(function(row){
str += row.desc.toFixedWidth(15," ","...") + delim
+ "$" + String(row.price).toFixedWidth(4)
})

parseJson

Converts a JSON (http://www.json.org) string into an object

Parameters

reviverOption, default date parser If specified, this function will be called called with (key,value) for every value in the generated object.  This can be used to “revive” custom serialized values embedded in JSON.  The default reviver restores dates in this format: “\/Date(1269727815826)\/” format, which is the format Object.toJson uses.

Returns

Number String Array or Object contained in the JSON text

Throws

SyntaxError if not properly formatted

Detail

Adapted from http://code.google.com/p/json-sans-eval/

This function expects strings to be properly formatted.  In particular watch out for property names, they must be quoted.

Bad:
{name:"bob"}

Good:
{"name":"bob"}

right

String.prototype.right=function(count)

returns the right side of a string

Parameters

countnumber of characters to return

Returns

The right count characters of string

repeat

String.prototype.repeat=function(count,
delimiter,
qualifier)

returns a copy of this string repeated count times

Parameters

countnumber of times to copy the provided string
delimiterOptional, default null string to put between each copy of the string.  This will not be placed at the ent of the returned string
qualifierOptional, default null string to put before and after each copy of the string

rpad

String.prototype.rpad=function(count,
padChar)

pads the right side of this string

Parameters

counttotal length after padding
padCharcharacter to pad with

Returns

padded string

Note

this is is an alias for <toFixedWidth>(count,_padChar_,null,”end”)

splitCap

String.prototype.splitCap=function splitCap(everyCap)

returns an array of the “words” in this string as delimited by Capital letters

Parameters

everyCapOptional, default false Normally groups of capital letters are treated as one term, i.e “personID” splits to [“person”,”ID”].  With this set to true, every capital letter will start a term such that “personID” splits to [“person”,”I”,”D”] Example:
"camelCasedProperty".splitCap(); //returns ["camel","Cased","Property"]

startsWith

String.prototype.startsWith = function(str,
caseSensitive)

returns true if this string starts with supplied string

Parameters

strstring to match
caseSensitiveOptional, default false Should the match be case sensitive?

See Also

Example

Myna.println(“BobDobb”.startsWith(“bob”))//prints true Myna.println(“BobDobb”.startsWith(“bob”,true))//prints false

titleCap

String.prototype.titleCap=function()

Capitalizes the first letter of every word in string

Returns

text with the first letter of every word captialized.

trim

String.prototype.trim=function()

returns a new string with beginning and trailing whitespace removed

trimIndent

String.prototype.trimIndent=function()

returns a new string with the initial white space on each line trimmed

This is useful for out-denting the entire string in situations where every line starts with the same unwanted whitespace.  This is automatically applied to ejs blocks so that they can be indented with the code without adding unwanted whitespace to the string.

Note

The string must start with an initial return (\n) followed by the regular whitespace (spaces and tabs) to replace.

Example

var offsetString = "\n\t\tline1\n\t\tline2\n\t\t\tsubline a\n\t\tline3";
Myna.print("before<br><pre>" + offsetString + "</pre>")
Myna.print("after<br><pre>" + offsetString.trimIndent() + "</pre>")

unEscapeHtml

String.prototype.unEscapeHtml=function(chars)

reverses the replacements in escapeHtml

Parameters

charsOptional default <htmlEscapeChars> string of characters to restore.  Leave this undefined to use the same set of characters as escapeHtml Returns: converted string

See

$req.data,<$req.rawData>,<escapeHtml>

checksum

String.prototype.checksum=function(algorithm,
urlSafe)

returns a simple String checksum(digest) for this string.

Parameters

algorithmOptional, default “MD5” Digest algorithm to use.
urlSafeOptional, default false If true, then the characters + and / and = will be replaced with
  • and _ and . respectively.  <JavaUtils.base64ToByteArray> will automatically detect this format, but it is non-standard so other libraries may not properly parse it.

Returns

Base64 encoded digest of this string

Detail

This uses any of the available Java hashing algorithms (MD5 be default) for quickly creating a unique string hash value.  This is useful for creating hash keys for lookup or equality comparisons or any other non-cryptographic uses.

For cryptographic uses see toHash

hashCode

String.prototype.hashCode=function()

returns java.lang.String.hasCode() for this string

Detail

The Java String object provides a method for quickly creating a unique numeric hash value.  This is useful for creating hash keys for lookup or equality comparisons or any other non-cryptographic uses.  Because this algorithm only returns a 32-bit integer, it has a relatively high chance of returning the same code for different strings.  checksum provides a less collision prone hash but returns a string

For For cryptographic uses see toHash

hashEquals

String.prototype.hashEquals=function(hash)

Returns true if the plaintext password matches the encrypted password

Parameters

hashhash previously created with <String.hash>

Returns

true if this string matches hash

Detail

One way hashes like those created by <String.hash> cannot be decrypted.  However, you can encrypt a possible match and compare the hashes.  Because of the salt in the hashes produced by <String.hash>, equivalent hashes won’t look the same, but this function can compare them.

See

toHash

String.prototype.toHash=function(urlSafe)

Returns a copy of this string encrypted with a strong one-way hash in base64 format.

Parameters

urlSafeOptional, default false If true, then the characters + and / and = will be replaced with

Returns

Encrypted password string in only printable characters.

Detail

This function encrypts the supplied text with a one-way algorithm so that it can never be converted back to the original text.  This can be any text but it makes the most sense for passwords.  Although you can’t tell what the original text is, you can compare the encrypted string to a plaintext string to see if they match.  See String.hashEquals.

For extra security, each hash includes a salt; a string characters appended to the text to force it to be unique.  This way even if an attacker can figure out that his/her password of “bob” = “tUhTivKWsIKE4IwVX9s/wzg1JKXMPU+C”, he or she will not be able to tell if any of the other hashes equal “bob”.  This makes a brute force dictionary attack much more difficult.

Example

<%="bob".toHash()%><br>
<%="bob".toHash()%><br>
<%="bob".toHash()%><br>
<%="bob".toHash()%><br>

..prints something like

tUhTivKWsIKE4IwVX9s/wzg1JKXMPU+C
M0y5EgZVG3iW2N5k2ipHp7x7JtvJYGu5
yRxnK/RlK9VeX89duVkrncQv4/vWyWGs
ca4r3Qlt51wFk/y0pv+7YazkcFtRgkoS

See

decrypt

String.prototype.decrypt=function(password)

Returns the unencrypted string contained in this string

Parameters

passwordPassword used to orginally encrypt the string

Returns

The unencrypted string contained in this string

See

encrypt

String.prototype.encrypt=function(password)

Encrypts this string using a password.

Parameters

passwordpassword to use for encryption.

Detail

This function provides simple password-based encryption of string values.  For more secure encryption using rotating database-backed keys see Myna.KeyStore

Returns

The encrypted string.

Example

<%="bob".encrypt("theSecretPassword")%><br>
<%="bob".encrypt("theSecretPassword")%><br>
<%="bob".encrypt("theSecretPassword")%><br>
<%="bob".encrypt("theSecretPassword")%><br>

.. might print

xeM5n1ncfX2KNTLUEjZHeg==
AedyMQ5jA1rbOdQZMTq9Ag==
+Zam3Jg4YqI/5QRkcokLcQ==
LY2OAW8+xe3I5OJi/Hg+6A==

See

pipe

String.prototype.pipe=function (cmd,
options)

alias for Myna.exec, using this contents of this string as the options.input

Parameters

See Myna.exec

Example

var sortedFiles = Myna.exec("ls -a",{dir:"/"}).pipe("egrep -v ~").pipe("sort -h");

toJava

String.prototype.toJava=function()

returns a new java.lang.String of this string

toXml

String.prototype.toXml=function()

returns an E4X XML object from this string, or throws an exception if not possible

See

toXmlDoc

String.prototype.toXmlDoc=function()

returns an org.w3c.dom.Document object from this string, or throws an exception if not possible

See

escapeUrl

String.prototype.escapeUrl=function()

returns a URL encoded version of this string

String.prototype.escapeHtml=function(string)
replaces common symbols with their HTML entity equivalents
String.prototype.unEscapeHtml=function(chars)
reverses the replacements in escapeHtml
String.prototype.after=function(count,
caseSensitive)
returns all the characters after the first count characters
String.prototype.before=function(count)
returns all the characters before the last count characters
String.charToHtmlEntity = function(c)
returns the HTML/XML entity of the supplied character in &#code; format where code is the decimal ASCII code
String.compareAlpha = function(a,
b)
Static A static sort function that will compare two strings by lexigraphical order.
String.compareAlphaNoCase = function(a,
b)
Static A case-insensitive version of String.compareAlpha
String.compareAlphaReverse = function(a,
b)
Static A descending version of compareAlpha.
String.compareAlphaReverseNoCase = function(a,
b)
Static A case-insensitive version of String.compareAlphaReverse
String.compareNatural = function(a,
b)
Static A static sort function that will compare two strings in a natural way.
String.compareNaturalNoCase = function(a,
b)
Static A case-insensitive version of String.compareNatural
String.compareNaturalReverse = function(a,
b)
Static A descending version of compareNatural.
String.compareNaturalReverseNoCase = function(a,
b)
Static A case-insensitive version of String.compareNaturalReverse
String.compareNumeric = function(a,
b)
Static A static sort function that will compare two strings by lexigraphical order.
String.compareNumericReverse = function(a,
b)
Static A descending version of compareNumeric.
String.prototype.endsWith = function(str,
caseSensitive)
returns true if this string ends with supplied string
String.prototype.escapeRegex=function(string)
returns string with symbols that might be interpreted as regex escaped
String.prototype.escapeJs=function()
returns string with symbols that might be interpreted as JavaScript escaped
String.prototype.format=function(values)
returns a string with parameters replaced
String.prototype.getLineIterator = function()
returns java Iterator that produces a line at a time for this string
String.htmlEntityToChar = function(e)
Static returns the chatacter representation of the supplied HTML/XML entity
String.prototype.left=function(count)
returns the left side of a string
String.prototype.lpad=function(count,
padChar)
pads the left side of this string
String.prototype.listAppend=function(val,
delimiter,
qualifier)
returns new list (string) with value appended (does not modify original string).
String.prototype.listAppendUnique=function(val,
delimiter,
qualifier)
returns new list (string) with value appended, if not already in list
String.prototype.listAppendUniqueNoCase=function(val,
delimiter,
qualifier)
returns new list (string) with value appended, if not already in list, ignoring case
String.prototype.listAfter=function(delimiter,
qualifier)
returns this list minus the first element.
String.prototype.listBefore=function(delimiter)
returns this list minus the last element.
String.prototype.listContains=function(val,
delimiter,
qualifier)
returns true if list contains the value.
String.prototype.listContainsNoCase=function(val,
delimiter,
qualifier)
returns true if list contains the value, ignoring case.
String.prototype.listFind=function(val,
startFrom,
delimiter,
qualifier)
returns the index of a value in a list
String.prototype.listFindNoCase=function(val,
startFrom,
delimiter,
qualifier)
returns the index of a value in a list, ignoring case
String.prototype.listFirst=function(delimiter,
qualifier)
returns the first value of a list.
String.prototype.listLast=function(delimiter,
qualifier)
returns the last value of a list.
String.prototype.listAt=function(position,
delimiter,
qualifier)
returns the list value at a specific location, or “”.
String.prototype.listLen=function(delimiter)
returns the length of a list
String.prototype.listMakeUnique=String.prototype.listGetUnique=function(
   delimiter
)
returns new list (string) with each item represented only once
String.prototype.listMakeUniqueNoCase=function(delimiter)
returns new list (string) with each item represented only once, regardless of case.
String.prototype.listQualify=function(symbol,
delimiter,
qualifier)
returns new list (string) with each item surrounded by a qualifying symbol
String.prototype.listSame=function(list,
delimiter)
returns true if the provided list contains the smae elements as this list regardless of order.
String.prototype.listSameNoCase=function(list,
delimiter)
returns true if the provided list contains the smae elements as this list regardless of order.
String.prototype.listSort=function(sortFunc,
delimiter,
qualifier)
returns a copy of this list sorted by the supplied sort function
String.prototype.listToArray=function(delimiter,
qualifier)
returns an array of the items in this list
String.prototype.toFixedWidth=function(count,
pad,
placeHolder,
truncateFrom)
returns this string padded/truncated to the specified length
String.prototype.right=function(count)
returns the right side of a string
String.prototype.repeat=function(count,
delimiter,
qualifier)
returns a copy of this string repeated count times
String.prototype.rpad=function(count,
padChar)
pads the right side of this string
String.prototype.splitCap=function splitCap(everyCap)
returns an array of the “words” in this string as delimited by Capital letters
String.prototype.startsWith = function(str,
caseSensitive)
returns true if this string starts with supplied string
String.prototype.titleCap=function()
Capitalizes the first letter of every word in string
String.prototype.trim=function()
returns a new string with beginning and trailing whitespace removed
String.prototype.trimIndent=function()
returns a new string with the initial white space on each line trimmed
String.prototype.checksum=function(algorithm,
urlSafe)
returns a simple String checksum(digest) for this string.
String.prototype.hashCode=function()
returns java.lang.String.hasCode() for this string
String.prototype.hashEquals=function(hash)
Returns true if the plaintext password matches the encrypted password
String.prototype.toHash=function(urlSafe)
Returns a copy of this string encrypted with a strong one-way hash in base64 format.
String.prototype.decrypt=function(password)
Returns the unencrypted string contained in this string
String.prototype.encrypt=function(password)
Encrypts this string using a password.
String.prototype.pipe=function (cmd,
options)
alias for Myna.exec, using this contents of this string as the options.input
String.prototype.toJava=function()
returns a new java.lang.String of this string
String.prototype.toXml=function()
returns an E4X XML object from this string, or throws an exception if not possible
String.prototype.toXmlDoc=function()
returns an org.w3c.dom.Document object from this string, or throws an exception if not possible
String.prototype.escapeUrl=function()
returns a URL encoded version of this string
Stores parameters to the request.
Myna.File.prototype.getLineIterator= function()
returns an interator object for looping one line at a time over the file without loading the entire file into memory.
Object.prototype.toJson=function(indent)
Converts the this object to JSON (http://www.json.org)
Manages keys sets and encypts,decrypts,signs,and verfies data.
Myna.exec = function exec(cmd,
options)
Execute a program and return the result