0% found this document useful (0 votes)
4 views2 pages

String Manipulation Function

The document provides a program demonstrating various string manipulation functions in R. It includes operations such as concatenation, substring extraction, case conversion, length calculation, splitting, and replacing characters. The output of each operation is displayed, showcasing the results of the string manipulations performed.

Uploaded by

mkachar671
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

String Manipulation Function

The document provides a program demonstrating various string manipulation functions in R. It includes operations such as concatenation, substring extraction, case conversion, length calculation, splitting, and replacing characters. The output of each operation is displayed, showcasing the results of the string manipulations performed.

Uploaded by

mkachar671
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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

You might also like