namespace SAPO.Utility.String
String utility function

Function Summary
escapes a unicode character. returns \xXX if hex smaller than 0x100, otherwise \uXXXX
String escapeText (String txt, [String[] whiteList])
escapes a string to unicode characters
eval a JSON string to a JS object
Convert listed HTML entities to character
Convert listed characters to HTML entities
escapes unsafe html chars to their entities
normalizes whitespace in string. string is trimmed and sequences of many whitespaces are collapsed.
Convert all accented chars to char without accent.
String shortString (String str, Number n)
Make a string shorter without cutting words
Number strcmp (String String, String String)
compares two strings
String stripTags (String string, [String strip])
Remove HTML tags of string
String substrCount (String haystack, String needle)
Count the number of occurrences of a specific needle in a haystack
String trim (String string)
Remove spaces and new line from biggin and ends of string
String truncateString (String str, Number length)
Truncates a string, breaking words and adding ... at the end
String ucFirst (String string)
Convert first letter of a word to upper case
If param as more than one word, it converts first letter of all words that have more than 2 letters
unescapes a unicode character escape sequence
unescapes a string
Decode a string from UTF8
utf8Encode (String string)
Encode a string to UTF8

Function Details

function escape

String escape(String c)
escapes a unicode character. returns \xXX if hex smaller than 0x100, otherwise \uXXXX
Parameters:
c char

function escapeText

String escapeText(String txt, [String[] whiteList])
escapes a string to unicode characters
Parameters:
txt
[whiteList]

function evalJSON

String evalJSON(String JSON)
eval a JSON string to a JS object
Parameters:
JSON
Returns:
object JS Object

function htmlEntitiesDecode

String htmlEntitiesDecode(String string)
Convert listed HTML entities to character
Parameters:
string
Returns:
string decoded

function htmlEntitiesEncode

String htmlEntitiesEncode(String string)
Convert listed characters to HTML entities
Parameters:
string
Returns:
string encoded

function htmlEscapeUnsafe

String htmlEscapeUnsafe(String string)
escapes unsafe html chars to their entities
Parameters:
string to escape
Returns:
new escaped string

function normalizeWhitespace

String normalizeWhitespace(String string)
normalizes whitespace in string. string is trimmed and sequences of many whitespaces are collapsed.
Parameters:
string to normalize
Returns:
new normalized string

function removeAccentedChars

String removeAccentedChars(String string)
Convert all accented chars to char without accent.
Parameters:
string
Returns:
string without accented chars

function shortString

String shortString(String str, Number n)
Make a string shorter without cutting words
Parameters:
str
n - number of chars of the short string
Returns:
string shorted

function strcmp

Number strcmp(String String, String String)
compares two strings
Parameters:
String to compare against
String to be compared

function stripTags

String stripTags(String string, [String strip])
Remove HTML tags of string
Parameters:
string
[strip] tagNames separated by comma ","
Returns:
without HTML tag var myvar='isto e um texto bold com imagem e br
um

paragrafo

'; SAPO.Utility.String.stripTags(myvar, 'b,u');

function substrCount

String substrCount(String haystack, String needle)
Count the number of occurrences of a specific needle in a haystack
Parameters:
haystack
needle
Returns:
int with number of occurrences

function trim

String trim(String string)
Remove spaces and new line from biggin and ends of string
Parameters:
string
Returns:
string trimmed

function truncateString

String truncateString(String str, Number length)
Truncates a string, breaking words and adding ... at the end
Parameters:
str
length - length limit for the string. String will be at most this big, ellipsis included.
Returns:
short string

function ucFirst

String ucFirst(String string)
Convert first letter of a word to upper case
If param as more than one word, it converts first letter of all words that have more than 2 letters
Parameters:
string
Returns:
{String} string camel case

function unescape

String unescape(String es)
unescapes a unicode character escape sequence
Parameters:
es escape sequence

function unescapeText

String unescapeText(String txt)
unescapes a string
Parameters:
txt

function utf8Decode

String utf8Decode(String string)
Decode a string from UTF8
Parameters:
string
Returns:
string utf8 decoded

function utf8Encode

utf8Encode(String string)
Encode a string to UTF8
Parameters:
string
Returns:
{String} string utf8 encoded