From 83b0c153d3e3fc9c6421d127c9e52eb538c0c85c Mon Sep 17 00:00:00 2001 From: Andrew Dupont Date: Fri, 4 Dec 2009 18:29:40 -0600 Subject: [PATCH] Add examples for String#gsub and String#sub. (cherry picked from commit 591b25eb2604953754f08c40e9ef99791a6bb51b) --- src/lang/string.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/lang/string.js b/src/lang/string.js index a7c0334..e581f63 100644 --- a/src/lang/string.js +++ b/src/lang/string.js @@ -42,6 +42,11 @@ Object.extend(String.prototype, (function() { * Returns the string with every occurence of a given pattern replaced by either * a regular string, the returned value of a function or a [[Template]] string. * The pattern can be a string or a regular expression. + * + *
Example
+ * + * ""hello".gsub(/([aeiou])/, '<#{1}>'); + * // => "hll" **/ function gsub(pattern, replacement) { var result = '', source = this, match; @@ -73,6 +78,11 @@ Object.extend(String.prototype, (function() { * 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. * The pattern can be a string or a regular expression. + * + *
Example
+ * + * "20091201".sub(/^(\d{4})(\d{2})(\d{2})$/, "#{1}-#{2}-#{3}"); + * // => "2009-12-01" **/ function sub(pattern, replacement, count) { replacement = prepareReplacement(replacement);