| String | Exemple |
Ph |
Commentaire |
Groupe |
| "%05d" % 22 | => "00022" | Format décimal aligné à droite et complété par des 0 | Formate | |
| "%-5d" % 22 | => "22 " | Format décimal aligné à gauche et complété par des blancs | Formate | |
| "%b" % 5 | => "101" | Format binaire | Formate | |
| "%x" % 255 | => "ff" | Format héxadécilmal | Formate | |
| "%.2f" % 3.1415 | => "3.14" | Format flottant avec 2 chiffres de précisions | Formate | |
| "ga" * 3 | => "gagaga" | Compose | ||
| "ga" + "bu" | => "gabu" | Compose | ||
| "ga" << "bu" | => "gabu" | W |
Compose | |
| "a" <=> "b" | => -1 | Compare | ||
| "b" <=> "a" | => 1 | Compare | ||
| "aa" <=> "a" | => 1 | Compare | ||
| "cd" <=> "cd" | => 0 | Compare | ||
| "cd" == "cd" | => true | Compare | ||
| 2 == "2" | => false | Compare | ||
| "abcdef" =~ /de/ | => 3 | Indice où c'est conforme à l'expression | Recherche | |
| "abcd"[0] | => "a" | Extrait | ||
| "abcd"[3] | => "d" | Extrait | ||
| "abcd"[4] | => nil | Extrait | ||
| "abcd"[-1] | => "d" | Extrait | ||
| "abcd"[-3] | => "a" | Extrait | ||
| "abcdef"[2..3] | => "cd" | Extrait | ||
| "abcdef"[2,3] | => "cde" | Extrait | ||
| "abcdef"[/cd/] | => "cd" | Extrait | ||
| "abcdef"[/cd/,1] | => nil | Extrait | ||
| s="abcde".[2..4]="A";s | => "abA" | W |
Extrait | |
| "ab".ascii_only? | => true | Compare | ||
| "abc".bytes | => #<Enumerator: "abc":bytes> | Enumère les octects | Enumère | |
| "abc".bytes{|x| p x} | => "abc" | Affiche les octects | Enumère | |
| "ab\u0321".bytesize | => 4 | Nombre d'octets | Recherche | |
| "bonjour".capitalize | => "Bonjour" | Formate | ||
| "BONJOUR".capitalize | => "Bonjour" | Formate | ||
| "123bonjour".capitalize | => "123bonjour" | Formate | ||
| s.capitalize! | W |
Formate | ||
| "ABC".casecmp("abc") | => 0 | Compare | ||
| "a".casecmp("b") | => -1 | Compare | ||
| "b".casecmp("a") | => 1 | Compare | ||
| "aa".casecmp("a") | => 1 | Compare | ||
| "toto".center(15) | => " toto " | Formate | ||
| "toto".center(15,"=/") | => "=/=/=toto=/=/=/" | Formate | ||
| "abc".chars | => #<Enumerator: "abc":chars> | Enumère les charactères | Enumère | |
| "abc".chars{|x| p x} | => "abc" | Affiche les caractères | Enumère | |
| "toto\r\n".chomp | => "toto" | Formate | ||
| "toto\r\n".chomp("to") | => "to" | Formate | ||
| s.chomp! | W | Formate | ||
| s.chomp!(r) | W | Formate | ||
| "abc".chop | => "ab" | Formate | ||
| s.chop! | Formate | |||
| "abc".chr | => "a" | Extrait | ||
| s.clear | => "" | W | Vide le contenu de s. | Extrait |
| "abc".codepoints | => #<Enumerator: "abc":codepoints> | Enumère les charactères en décimals | Enumère | |
| "abc".codepoints{|x| p x} | Affiche les caractères en décimals | Enumère | ||
| "ab".concat("fg") | => "abfg" | W | Compose | |
| "abcab".count("ab") | => 4 | Recherche | ||
| "abcab".count("ab","bc","ba") | => 2 | (intersection) | Recherche | |
| "abcab".count("abc","^ab") | => 1 | (moins) | Recherche | |
| "toto".crypt("terre") | => "tegNlzW5VjNcM" | Converti | ||
| "abcab".delete("ab") | => "c" | Extrait | ||
| "abcab".delete("ab","bc","ba") | => "aca" | Extrait | ||
| "abcab".delete("abc","^ab") | => "abab" | Extrait | ||
| s.delete!(u,v,w...) | W | Extrait | ||
| "HELLO".downcase | => "hello" | Compose | ||
| s.downcase! | W | Compose | ||
| "aaa\naaa".dump | =>"\"aaa\\naaa\"" | Formate | ||
| "abc".each_byte | => #<Enumerator: "abc":each_byte> | Enumère les octects | Enumère | |
| "abc".each_char | => #<Enumerator: "abc":each_char> | Enumère les caractères | Enumère | |
| "abc".each_codepoint | => #<Enumerator: "abc":each_codepoint> | Enumère les caractères en décimals | Enumère | |
| "ab\ncd".each_line | => #<Enumerator: "ab\ncd":each_line> | Enumère les lignes | Enumére | |
| "abab".each_line("ba") | => #<Enumerator: "ab\ncd":each_line("ba")> | Enumère les portions se finissant par "ba" | Enumère | |
| "".empty? | => true | Compare | ||
| "ab".encode("utf-8") | => "ab" | Formate | ||
| "ab".encode("iso-8859-2","utf-8") | => "ab" | transforme de l'utf-8 en de l'iso-8859-2 | Formate | |
| s.encode!(dst,src) | W | Formate | ||
| "ab".encoding | => #<Encoding:UTF-8> | Retourne l'Encodingde de la chaine "ab" | Formate | |
| "abcd".end_with?("cd","fg") | => true | Compare | ||
| "ab".eql?("ab") | => true | Compare | ||
| "ab".force_encoding("utf-8") | => "ab" | Force l'encodage en utf-8 | Formate | |
| "abc".getbyte(1) | => 98 | L'octet en décimals qui est à la position 1. ("b"=98) | Extrait | |
| "ababa".gsub(/a/, "GG") | => "GGbGGbGG" | Enumère | ||
| "abcabc".gsub(/a/) | => #<Enumerator: "abcabc":gsub(/a/)> | Enumère | ||
| "hello".gsub(/e|o/){|x| x+x} | => "heelloo" | Enumère | ||
| s.gsub! | W | Enumère | ||
| "ab".hash | => -565794218 | hachage sur 32 bits | Converti | |
| "ff".hex | => 255 | Converti | ||
| "0xFFFF".hex | => 65535 | Converti | ||
| "-f".hex | => -15 | Converti | ||
| "hello".include?("lo") | => true | Compare | ||
| "hello".index("e") | => 1 | Recherche | ||
| "hello".index("lo") | => 3 | Recherche | ||
| "hello".index(/e|o/, 2) | => 4 | Recherche | ||
| "abc".insert(0,"X") | => "Xabc" | W | Extrait | |
| "abc".insert(3,"X") | => "abcX" | W | Extrait | |
| "abc".insert(-1,"X") | => "abcX" | W | Extrait | |
| "aaa\naaa".inspect | =>"\"aaa\\naaa\"" | Formate | ||
| "ab".intern | => :ab | Converti | ||
| "ab.length. | => 2 | Recherche | ||
| "ababa".lines("ba") | => #<Enumerator: "ababa":lines("ba")> | Enumère les portions se finissant par "ba" | Enumère | |
| "ababa".lines("ba"){|x| p x} | Affiche les portions se finissant par "ba" | Enumère | ||
| "toto".ljust(10) | => "hello " | Aligner à gauche | Formate | |
| "toto".ljust(10,"123") | => "hello12312" | Aligner à gauche et complété par "123" | Formate | |
| " abc".lstrip | => "abc" | Formate | ||
| s.lstrip! | W | Formate | ||
| "aaub".match("a(.)b") | => #<MatchData "aub" 1:"u"> | Enumère | ||
| "aaub".match("a(.)b")[1] | => "u" | Enumère | ||
| "a".next | => "b" | Compose | ||
| "1".next | => "2" | Compose | ||
| "zz".next | => "aaa" | Compose | ||
| "99".next | => "100" | Compose | ||
| "a9".next | => "b0" | Compose | ||
| s.next! | W | Compose | ||
| "a".ord | => 97 | Converti | ||
| "bonjour".partition("jo") | => ["bon", "jo", "ur"] | Converti | ||
| "bonjour".partition(/o.*o/) | => ["b", "onjo", "ur"] | Converti | ||
| s.replace("abc") | => "abc" | W | Remplace le contenu de s par "abc" | Extrait |
| "123".reverse | => "321" | Compose | ||
| s.reverse! | W | Compose | ||
| "ababab".rindex("ab") | => 4 | Recherche | ||
| "abab".rindex(/a/,1) | => 0 | Recherche | ||
| "toto".rjust(10) | => " hello" | Aligner à droite | Formate | |
| "toto".rjust(10,"123") | => "12312hello" | Aligner à droite et complété par "123" | Formate | |
| "hello".rpartition("l") | => ["hel", "l", "o"] | Converti | ||
| "abc ".rstrip | => "abc" | Formate | ||
| s.rstrip! | W | Formate | ||
| "ab uvw".scan(/\w+/) | => ["ab", "uvw"] | Converti | ||
| "abctoto aaa".scan(/a../) | => ["abc", "aaa"] | Converti | ||
| "a25fra78f".scan(/a(.)(.)f/) | => [["2", "5"], ["7", "8"]] | Converti | ||
| s.scan(/a(.)(.)f/){|x,y| print y,x} | Converti | |||
| s="pp"; s.setbyte(1,97); s | => "pa" | W | Extrait | |
| "abc".size | => 3 | Recherche | ||
| "abc".slice(1) | => "b" | Extrait | ||
| "abc".slice(1..2) | => "bc" | Extrait | ||
| s="pqr"; s.slice!(1); s | => "pr" | W | Extrait | |
| "ab toto titi".split | => [ "ab", "toto", "titi"] | Converti | ||
| "5ab12ab23".split("ab") | => ["5", "12", "23"] | Converti | ||
| "5u12v23".split(/u|v/) | => ["5", "12", "23"] | Converti | ||
| "1a2a3a4a5".split("a",3) | => ["1", "2", "3a4a5"] | Converti | ||
| "abbbolli".squeeze | =>"aboli" | Compose | ||
| "aaaabbbbeeee".squeeze("a-d") | "abeeee" | Compose | ||
| "aaaabbbbeeee".squeeze("ab") | "abeeee" | Compose | ||
| s.squeeze! | W | Compose | ||
| "abc".start_with?("ab","cd") | => true | Compare | ||
| " abc ".strip | => "abc" | Formate | ||
| s.strip! | W | Formate | ||
| "hello".sub(/[aeiou]/,"-") | => "h-llo" | Extrait | ||
| "hello".sub(/[aeiou]/){|x| x.capitalize} | => "hEllo" | Extrait | ||
| s.sub!(...) | W | Extrait | ||
| "aa".succ | =>"ab" | Compose | ||
| s.succ! | W | Compose | ||
| "aBcD".swapcase | => "AbCd" | Compose | ||
| s.swapcase! | W | Compose | ||
| "2+3i".to_c | => (2+3i) | Converti | ||
| "12.5e3".to_f | => 12500.0 | Converti | ||
| "123ab".to_i | => 123 | Converti | ||
| "11111111".to_i(2) | => 255 | Converti | ||
| "FFFF".to_i(16) | => 65535 | Converti | ||
| "ab".to_s | => "ab" | Converti | ||
| "ab".to_str | => "ab" | Converti | ||
| "ab".to_sym | => :ab | Converti | ||
| "abcaaa".tr("abc","uvw") | => "uvwuuu" | Compose | ||
| s.tr!(...) | W | Compose | ||
| "ab".upcase | => "AB" | Compose | ||
| s.upcase! | W | Compose | ||
| "a9".upto("aaa0") | => #<Enumerator: "a9":upto("aaa")> | Enumère | ||
| "a9".upto("aaa0"){|x| p x} | => "a9" | Enumère |