5. String Manipulation function.
PROGRAM:-
str1 <- "Hello"
str2 <- "World"
cat("Paste:", paste(str1, str2), "\n")
cat("Paste0:", paste0(str1, str2), "\n")
cat("Substring:", substr("OpenAI",1,4), "\n")
text <- "Hello World"
cat("Upper:", toupper(text), "\n")
cat("Lower:", tolower(text), "\n")
cat("Length:", nchar("OpenAI"), "\n")
print(strsplit("Hello,World", ","))
cat("Replace one:", sub("World","R",text), "\n")
cat("Replace all:", gsub("o","0",text), "\n")
cat("Trim:", trimws(" Hello "), "\n")
cat("Repeat:", strrep("Hi",3), "\n")
OUTPUT:-
Paste: Hello World
Paste0: HelloWorld
Substring: Open
Upper: HELLO WORLD
Lower: hello world
Length: 6
[[1]]
[1] "Hello" "World"
Replace one: Hello R
Replace all: Hell0 W0rld
Trim: Hello
Repeat: HiHiHi