summaryrefslogtreecommitdiff
path: root/doc/string/scrub.rdoc
diff options
context:
space:
mode:
Diffstat (limited to 'doc/string/scrub.rdoc')
-rw-r--r--doc/string/scrub.rdoc22
1 files changed, 22 insertions, 0 deletions
diff --git a/doc/string/scrub.rdoc b/doc/string/scrub.rdoc
new file mode 100644
index 0000000000..314b28c465
--- /dev/null
+++ b/doc/string/scrub.rdoc
@@ -0,0 +1,22 @@
+Returns a copy of +self+ with each invalid byte sequence replaced
+by the given +replacement_string+.
+
+With no block given, replaces each invalid sequence
+with the given +default_replacement_string+
+(by default, <tt>"�"</tt> for a Unicode encoding, <tt>'?'</tt> otherwise):
+
+ "foo\x81\x81bar".scrub # => "foo��bar"
+ "foo\x81\x81bar".force_encoding('US-ASCII').scrub # => "foo??bar"
+ "foo\x81\x81bar".scrub('xyzzy') # => "fooxyzzyxyzzybar"
+
+With a block given, calls the block with each invalid sequence,
+and replaces that sequence with the return value of the block:
+
+ "foo\x81\x81bar".scrub {|sequence| p sequence; 'XYZZY' } # => "fooXYZZYXYZZYbar"
+
+Output :
+
+ "\x81"
+ "\x81"
+
+Related: see {Converting to New String}[rdoc-ref:String@Converting+to+New+String].