Trim a String to a Specified Display Width in R Programming - strtrim() Function Last Updated : 12 Jun, 2020 Comments Improve Suggest changes Like Article Like Report strtrim() function in R Language is used to trim a string to a specified display width. Syntax: strtrim(x, width) Parameters: x: character vector width: specified width Example 1: Python3 1== # R program to trim a string # to specified width # Creating a vector x1 <- "GeeksforGeeks" x2 <- "R Programming" # Calling strtrim() function strtrim(x1, 5) strtrim(x2, 7) Output: [1] "Geeks" [1] "R Progr" Example 2: Python3 1== # R program to trim a string # to specified width # Creating a vector x <- c("Hello", "Geeks", "GFG") # Calling strtrim() function strtrim(x, 2) strtrim(x, c(1, 2, 3)) Output: [1] "He" "Ge" "GF" [1] "H" "Ge" "GFG" Comment More infoAdvertise with us Next Article Trim a String to a Specified Display Width in R Programming - strtrim() Function N nidhi_biet Follow Improve Article Tags : R Language R String-Functions Similar Reads Create Repetitions of a String in R Programming - strrep() Function strrep() Function in R Language is used to create specified number of repetitions of a specified string. Syntax: strrep(string, n) Parameter: string: specified string n: number of repetitions Example 1: Python3 1== # R Program to illustrate # the use of strrep function # String to be repeated x < 1 min read Convert an Object to a String in R Programming - toString() Function toString() function in R Language is used to convert an object into a single character string. Syntax: toString(x, width) Parameters: x: Object width: maximum string width Example 1: Python3 1== # R program to convert an object to string # Creating a vector x <- c("Geeks", "for 1 min read Convert String to Integer in R Programming - strtoi() Function strtoi() function in R Language is used to convert the specified string to integers. Syntax: strtoi(x, base=0L) Parameters: x: character vector base: integer between 2 and 36 inclusive, default is 0 Example 1: Python3 # R program to illustrate # strtoi function # Initializing some string vector x 1 min read Print a Formatted string in R Programming - sprintf() Function The sprintf() function is used to create formatted strings in R. These formatted strings enable us to insert variables and values into a string while controlling their appearance and formatting. The sprintf() function uses a user-defined format to return a formatted string by inserting the correspon 2 min read Extracting Substrings from a Character Vector in R Programming - substring() Function substring() function in R Programming Language is used to extract substrings in a character vector. You can easily extract the required substring or character from the given string. Syntax: substring(text, first, last) Parameters:Â text: character vectorfirst: integer, the first element to be replac 1 min read Like