Ruby | String getbyte Method Last Updated : 12 Dec, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report getbyte is a String class method in Ruby which is used to return the indexth byte as an integer. Syntax: str.getbyte(index) Parameters: Here, str is the given string. Returns: Indexth byte as an integer. Example 1: Ruby # Ruby program to demonstrate # the getbyte method # Taking a string and # using the method puts "Ruby".getbyte(1) puts "String".getbyte(4) Output: 117 110 Example 2: Ruby # Ruby program to demonstrate # the getbyte method # Taking a string and # using the method # it will return nil puts "Sample".getbyte(7) puts "Program".getbyte(4) Output: 114 Comment More infoAdvertise with us Next Article Ruby | String bytesize method K Kirti_Mangal Follow Improve Article Tags : Ruby Ruby-Methods Ruby String-class Similar Reads Ruby | String bytes Method bytes is a String class method in Ruby which is used to return an array of the bytes for the given string. Syntax: str.bytes Parameters: Here, str is the specified string. Returns: An array of bytes. Example 1: Ruby # Ruby program to demonstrate # the bytes method # Taking a string and # using the m 1 min read Ruby | String <=> Method <=>() is a String class method in Ruby which is used for comparisons of the strings. This method returns -1, 0, +1, or nil depending on whether the specified string is less than, equal to, or greater than other_string. Syntax: str other_string Parameters: Here, str and other_string are the str 1 min read Ruby | String empty? Method empty? is a String class method in Ruby which is used to check whether the string length is zero or not. Syntax: str.empty? Parameters: Here, str is the given string which is to be checked. Returns: It returns true if str has a length of zero, otherwise false. Example 1: Ruby # Ruby program to demon 1 min read Ruby | String bytesize method bytesize is a String class method in Ruby which is used to get the length of the given string in bytes. Syntax: str.bytesize Parameters: Here, str is the given string. Returns: This method returns the length of the str in bytes. Example 1: Ruby # Ruby program to demonstrate # the bytesize method # T 1 min read Ruby | String gsub! Method gsub! is a String class method in Ruby which is used to return a copy of the given string with all occurrences of pattern substituted for the second argument. If no substitutions were performed, then it will return nil. If no block and no replacement is given, an enumerator is returned instead. Synt 1 min read Ruby | String gsub Method gsub is a String class method in Ruby which is used to return a copy of the given string with all occurrences of pattern substituted for the second argument. Syntax: str.gsub(pattern, replacement) Parameters: Here, str is the given string. pattern may be specified regex or character set to be remove 1 min read Like