APIdock / Ruby
/
Browse About
method

valid_encoding?

v1_9_3_392 - Show latest stable - Class: String
valid_encoding?()
public

Returns true for a string which encoded correctly.

"\xc2\xa1".force_encoding("UTF-8").valid_encoding?  #=> true
"\xc2".force_encoding("UTF-8").valid_encoding?      #=> false
"\x80".force_encoding("UTF-8").valid_encoding?      #=> false
static VALUE
rb_str_valid_encoding_p(VALUE str)
{
    int cr = rb_enc_str_coderange(str);

    return cr == ENC_CODERANGE_BROKEN ? Qfalse : Qtrue;
}

Related methods

  • Instance methods
  • %
  • *
  • +
  • <<
  • <=>
  • ==
  • ===
  • =~
  • []
  • []=
  • ascii_only?
  • block_scanf
  • bytes
  • bytesize
  • byteslice
  • capitalize
  • capitalize!
  • casecmp
  • center
  • chars
  • chomp
  • chomp!
  • chop
  • chop!
  • chr
  • clear
  • codepoints
  • concat
  • count
  • crypt
  • delete
  • delete!
  • downcase
  • downcase!
  • dump
  • each_byte
  • each_char
  • each_codepoint
  • each_line
  • empty?
  • encode
  • encode!
  • encoding
  • end_with?
  • eql?
  • ext
  • force_encoding
  • getbyte
  • gsub
  • gsub!
  • hash
  • hex
  • include?
  • index
  • initialize_copy
  • insert
  • inspect
  • intern
  • iseuc
  • isjis
  • issjis
  • isutf8
  • kconv
  • length
  • lines
  • ljust
  • lstrip
  • lstrip!
  • match
  • next
  • next!
  • oct
  • ord
  • parse_csv
  • partition
  • pathmap
  • pathmap_explode
  • pathmap_partial
  • pathmap_replace
  • prepend
  • replace
  • reverse
  • reverse!
  • rindex
  • rjust
  • rpartition
  • rstrip
  • rstrip!
  • scan
  • scanf
  • setbyte
  • shellescape
  • shellsplit
  • size
  • slice
  • slice!
  • split
  • squeeze
  • squeeze!
  • start_with?
  • strip
  • strip!
  • sub
  • sub!
  • succ
  • succ!
  • sum
  • swapcase
  • swapcase!
  • to_c
  • to_d
  • to_f
  • to_i
  • to_r
  • to_s
  • to_str
  • to_sym
  • toeuc
  • tojis
  • tolocale
  • tosjis
  • toutf16
  • toutf32
  • toutf8
  • tr
  • tr!
  • tr_s
  • tr_s!
  • unpack
  • upcase
  • upcase!
  • upto
  • valid_encoding?
  • Class methods
  • new
  • try_convert
APIdock API Documentation Browser

© 2026 APIdock