Prototype – Strings Processing


Prototype – String Processing


”;


Prototype enhances the String object with a series of useful methods ranging from the trivial to the complex.

Here is the list of all the functions with examples dealing with String.

Prototype String Methods

NOTE − Make sure you have the prototype.js version of 1.6.

S.No. Method & Description
1. blank()

Checks if the string is ”blank”, meaning either empty or containing only whitespace.

2. camelize()

Converts a string separated by dashes into a camelCase equivalent. For instance, ”foo-bar” would be converted to ”fooBar”.

3. capitalize()

Capitalizes the first letter of a string and downcases all the others.

4. dasherize()

Replaces every instance of the underscore character (“_”) by a dash (“-“).

5. empty()

Checks if the string is empty.

6. endsWith()

Checks if the string ends with substring.

7. escapeHTML()

Converts HTML special characters to their entity equivalents.

8. evalJSON()

Evaluates the JSON in the string and returns the resulting object.

9. evalScripts()

Evaluates the content of any script block present in the string. Returns an array containing the value returned by each script.

10. extractScripts()

Extracts the content of any script block present in the string and returns them as an array of strings.

11. gsub()

Returns the string with every occurrence of a given pattern replaced by either a regular string, the returned value of a function or a Template string.

12. include()

Checks if the string contains a substring.

13. inspect()

Returns a debug-oriented version of the string.

14. interpolate()

Treats the string as a Template and fills it with object”s properties.

15. isJSON()

Checks if the string is valid JSON by the use of regular expressions. This security method is called internally.

16. parseQuery()

Parses a URI-like query string and returns an object composed of parameter/value pairs.

17. scan()

Allows iterating over every occurrence of the given pattern.

18. startsWith()

Checks if the string starts with substring.

19. strip()

Strips all the leading and trailing whitespace from a string.

20. stripScripts()

Strips a string of anything that looks like an HTML script block.

21. stripTags()

Strips a string of any HTML tag.

22. sub()

Returns a string with the first count occurrences of pattern replaced by either a regular string, the returned value of a function or a Template string.

23. succ()

Used internally by ObjectRange. Converts the last character of the string to the following character in the Unicode alphabet.

24. times()

Concatenates the string count times.

25. toArray()

Splits the string character-by-character and returns an array with the result.

26. toJSON()

Returns a JSON string.

27. toQueryParams()

Parses a URI-like query string and returns an object composed of parameter/value pairs.

28. truncate()

Truncates a string to the given length and appends a suffix to it (indicating that it is only an excerpt).

29. underscore()

Converts a camelized string into a series of words separated by an underscore (“_”).

30. unescapeHTML()

Strips tags and converts the entity forms of special HTML characters to their normal form.

31. unfilterJSON ()

Strips comment delimiters around Ajax JSON or JavaScript responses. This security method is called internally.

Advertisements

”;

Leave a Reply

Your email address will not be published. Required fields are marked *