class String
Description
Extensions to the built-in String class.
Prototype enhances the String object with a series of useful methods for
ranging from the trivial to the complex. Tired of stripping trailing
whitespace? Try String#strip. Want to replace replace? Have a look at
String#sub and String#gsub. Need to parse a query string? We have
String#toQueryParams.
Methods
Instance methods
-
blank
String#blank() -> BooleanCheck if the string is 'blank', meaning either empty or containing only whitespace.
-
camelize
String#camelize() -> StringConverts a string separated by dashes into a camelCase equivalent. For instance, 'foo-bar' would be converted to 'fooBar'.
-
capitalize
String#capitalize() -> StringCapitalizes the first letter of a string and downcases all the others.
-
dasherize
String#dasherize() -> StringReplaces every instance of the underscore character ("_") by a dash ("-").
-
empty
String#empty() -> BooleanChecks if the string is empty.
-
endsWith
String#endsWith(substring) -> BooleanChecks if the string ends with substring.
-
escapeHTML
String#escapeHTML() -> StringConverts HTML special characters to their entity equivalents.
-
evalJSON
String#evalJSON([sanitize = false]) -> objectEvaluates the JSON in the string and returns the resulting object. If the optional sanitize parameter is set to true, the string is checked for possible malicious attempts and eval is not called if one is detected.
-
evalScripts
String#evalScripts() -> ArrayEvaluates the content of any script block present in the string. Returns an array containing the value returned by each script.
-
extractScripts
String#extractScripts() -> ArrayExctracts the content of any script block present in the string and returns them as an array of strings.
-
gsub
String#gsub(pattern, replacement) -> StringReturns the string with every occurence of a given pattern replaced by either a regular string, the returned value of a function or a
Templatestring. The pattern can be a string or a regular expression. -
include
String#include(substring) -> BooleanCheck if the string contains a substring.
-
inspect
String#inspect([useDoubleQuotes = false]) -> StringReturns a debug-oriented version of the string (i.e. wrapped in single or double quotes, with backslashes and quotes escaped).
-
interpolate
String#interpolate(object[, pattern]) -> StringTreats the string as a Template and fills it with object’s properties.
-
isJSON
String#isJSON() -> BooleanCheck if the string is valid JSON by the use of regular expressions. This security method is called internally.
-
scan
String#scan(pattern, iterator) -> StringAllows iterating over every occurrence of the given pattern (which can be a string or a regular expression). Returns the original string.
-
startsWith
String#startsWith(substring) -> BooleanChecks if the string starts with substring.
-
strip
String#strip() -> StringStrips all leading and trailing whitespace from a string.
-
stripScripts
String#stripScripts() -> StringStrips a string of anything that looks like an HTML script block.
-
stripTags
String#stripTags() -> StringStrips a string of any HTML tag.
-
sub
String#sub(pattern, replacement[, count = 1]) -> StringReturns a string with the first count occurrences of pattern replaced by either a regular string, the returned value of a function or a
Templatestring. The pattern can be a string or a regular expression. -
succ
String#succ() -> StringUsed internally by ObjectRange. Converts the last character of the string to the following character in the Unicode alphabet.
-
times
String#times(count) -> StringConcatenates the string
counttimes. -
toArray
String#toArray() -> ArraySplits the string character-by-character and returns an array with the result.
-
toJSON
String#toJSON() -> StringReturns a JSON string.
-
toQueryParams
String#toQueryParams([separator = '&']) -> ObjectParses a URI-like query string and returns an object composed of parameter/value pairs.
Alias of:
-
truncate
String#truncate([length = 30[, suffix = '...']]) -> StringTruncates a string to given
lengthand appendssuffixto it (indicating that it is only an excerpt). -
underscore
String#underscore() -> StringConverts a camelized string into a series of words separated by an underscore ("_").
-
unescapeHTML
String#unescapeHTML() -> StringStrips tags and converts the entity forms of special HTML characters to their normal form.
-
unfilterJSON
String#unfilterJSON([filter = Prototype.JSONFilter]) -> StringStrips comment delimiters around Ajax JSON or JavaScript responses. This security method is called internally.
Class methods
-
interpret
String.interpret(value) -> StringCoerces
valueinto a string. Returns an empty string fornull.
