namespace
SAPO.Utility.String
String utility function
Function Summary
escapes a unicode character. returns \xXX if hex smaller than 0x100, otherwise \uXXXX
escapes a string to unicode characters
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.
Make a string shorter without cutting words
Count the number of occurrences of a specific needle in a haystack
Truncates a string, breaking words and adding ... at the end
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
If param as more than one word, it converts first letter of all words that have more than 2 letters
unescapes a string
Decode a string from UTF8
utf8Encode
(String
string)
Encode a string to UTF8
Function Details
function escape
escapes a unicode character. returns \xXX if hex smaller than 0x100, otherwise \uXXXX
Parameters:
c
char function escapeText
escapes a string to unicode characters
Parameters:
txt
[whiteList]
function evalJSON
eval a JSON string to a JS object
Parameters:
JSON
Returns:
object JS Object
function htmlEntitiesDecode
Convert listed HTML entities to character
Parameters:
string
Returns:
string decoded
function htmlEntitiesEncode
Convert listed characters to HTML entities
Parameters:
string
Returns:
string encoded
function htmlEscapeUnsafe
escapes unsafe html chars to their entities
Parameters:
string
to escape
Returns:
new escaped string
function normalizeWhitespace
normalizes whitespace in string.
string is trimmed and sequences of many
whitespaces are collapsed.
Parameters:
string
to normalize
Returns:
new normalized string
function removeAccentedChars
Convert all accented chars to char without accent.
Parameters:
string
Returns:
string without accented chars
function shortString
Make a string shorter without cutting words
Parameters:
str
n
- number of chars of the short string
Returns:
string shorted
function strcmp
compares two strings
Parameters:
String
to compare against
String
to be compared function stripTags
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
um
paragrafo
'; SAPO.Utility.String.stripTags(myvar, 'b,u');function substrCount
Count the number of occurrences of a specific needle in a haystack
Parameters:
haystack
needle
Returns:
int with number of occurrences
function trim
Remove spaces and new line from biggin and ends of string
Parameters:
string
Returns:
string trimmed
function truncateString
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
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
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
unescapes a unicode character escape sequence
Parameters:
es
escape sequence function unescapeText
unescapes a string
Parameters:
txt
function utf8Decode
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