Ruby | String center() method Last Updated : 07 Jan, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report center is a String class method in Ruby which is used to centers the given string in width. If the specified width is greater than the length of the given string, then this method will return a new string of the specified width with the given string centered and padded otherwise it returns only given string. Syntax: str.center(width, padstr='')->new_str Parameters: Here, str is the given string and width is the specified width used to center the string. Returns: This method can either return a new modified string new_str or the same string. Example 1: Ruby #ruby 2.3.1 # Ruby program to demonstrate # the center method # Taking a string and # using the method puts "String".center(5) puts "Methods".center(18) Output: String Methods Example 2: Ruby #ruby 2.3.1 # Ruby program to demonstrate # the center method # Taking a string and # using the method puts "Ruby".center(9, '456') puts "String Class".center(18, '789') Output: 45Ruby456 789String Class789 Comment More infoAdvertise with us Next Article Ruby | String length Method K Kirti_Mangal Follow Improve Article Tags : Ruby Ruby-Methods Ruby String-class Similar Reads Ruby | String count() Method count is a String class method in Ruby. In this method each parameter defines a set of characters to which is to be counted. The intersection of these sets defines the characters to count in the given string. Any other string which starts with a caret ^ is negated. Syntax:str.count(parameter_list) P 1 min read Ruby | String chr Method chr is a String class method in Ruby which is used to return a one-character string at the beginning of the string. Syntax:str.chr Parameters: Here, str is the given string. Returns: A one-character string at the beginning of the string. Example 1: Ruby # Ruby program to demonstrate # the chr method 1 min read Ruby | String insert Method insert is a String class method in Ruby which is used to inserts the specified string before the character at the given index, modifying the given one. Negative indices count from the end of the string, and insert after the given character. Syntax: str.insert(index, other_str) Parameters: Here, str 1 min read Ruby | String length Method length is a String class method in Ruby which is used to find the character length of the given string. Syntax: str.length Parameters: Here, str is the string whose length is to be calculated Returns:It will return the character length of the str. Example 1: Ruby # Ruby program to demonstrate # the 1 min read Ruby | String concat Method concat is a String class method in Ruby which is used to Concatenates two objects of String. If the given object is an Integer, then it is considered a codepoint and converted to a character before concatenation. Syntax:String_Object.concat(String_Object) Parameters: This method can take the string 1 min read Ruby | String delete() Method delete is a String class method in Ruby which is used to return a copy of the given string with all characters in the intersection of its arguments deleted. Syntax: str.delete(parameter_list) Parameters: Here, str is the given string and parameter_list are the specified characters. Returns: A new co 1 min read Like