- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to split string values that contain special characters in R?
When we have a single long string or a vector of string values and the values within the string are separated by some special characters then splitting the values can help us to properly understand those strings. This could happen in situations when the string data is recorded with mistakes or have some other purpose. We can do the splitting using strsplit function.
Example
x1<-"tutorialspoint is an E-learning platform/FREE" x1
Output
[1] "tutorialspoint is an E-learning platform/FREE"
strsplit(x1,split='/',fixed=TRUE) [[1]] [1] "tutorialspoint is an E-learning platform" [2] "FREE"
Example
x2<-"tutorialspoint is an E-learning platform&FREE" x2
Output
[1] "tutorialspoint is an E-learning platform&FREE"
strsplit(x2,split='&',fixed=TRUE) [[1]] [1] "tutorialspoint is an E-learning platform" [2] "FREE"
Example
x3<-"tutorialspoint is an E-learning platform !FREE" x3
Output
[1] "tutorialspoint is an E-learning platform !FREE"
strsplit(x3,split='!',fixed=TRUE) [[1]] [1] "tutorialspoint is an E-learning platform " [2] "FREE"
Example
x4<-"tutorialspoint is an E-learning platform @FREE" x4
Output
[1] "tutorialspoint is an E-learning platform @FREE"
strsplit(x4,split='@',fixed=TRUE) [[1]] [1] "tutorialspoint is an E-learning platform " [2] "FREE"
Example
x5<-"tutorialspoint is an E-learning platform #FREE" x5
Output
[1] "tutorialspoint is an E-learning platform #FREE"
strsplit(x5,split='#',fixed=TRUE) [[1]] [1] "tutorialspoint is an E-learning platform " [2] "FREE"
Example
x6<-"tutorialspoint is an E-learning platform $FREE" x6
Output
[1] "tutorialspoint is an E-learning platform $FREE"
strsplit(x6,split='$',fixed=TRUE) [[1]] [1] "tutorialspoint is an E-learning platform " [2] "FREE"
Example
x7<-"tutorialspoint is an E-learning platform%FREE" x7
Output
[1] "tutorialspoint is an E-learning platform%FREE"
strsplit(x7,split='%',fixed=TRUE) [[1]] [1] "tutorialspoint is an E-learning platform" [2] "FREE"
Example
x8<-"tutorialspoint is an E-learning platform^FREE" x8
Output
[1] "tutorialspoint is an E-learning platform^FREE"
strsplit(x8,split='^',fixed=TRUE) [[1]] [1] "tutorialspoint is an E-learning platform" [2] "FREE"
Example
x9<-"tutorialspoint is an E-learning platform()FREE" x9
Output
[1] "tutorialspoint is an E-learning platform()FREE"
strsplit(x9,split='()',fixed=TRUE) [[1]] [1] "tutorialspoint is an E-learning platform" [2] "FREE"
Example
x10<-"tutorialspoint is an E-learning platform:FREE" x10
Output
[1] "tutorialspoint is an E-learning platform:FREE"
strsplit(x10,split=':',fixed=TRUE) [[1]] [1] "tutorialspoint is an E-learning platform" [2] "FREE"
Example
x11<-"tutorialspoint is an E-learning platform{}FREE" x11
Output
[1] "tutorialspoint is an E-learning platform{}FREE"
strsplit(x11,split='{}',fixed=TRUE) [[1]] [1] "tutorialspoint is an E-learning platform" [2] "FREE"
Example
x12<-"tutorialspoint is an E-learning platform***FREE" x12
Output
[1] "tutorialspoint is an E-learning platform***FREE"
strsplit(x12,split='***',fixed=TRUE) [[1]] [1] "tutorialspoint is an E-learning platform" [2] "FREE"
Example
x13<-c("tutorialspoint ^ is", "an ^ E-learning", "platform ^ & FREE") x13
Output
[1] "tutorialspoint ^ is" "an ^ E-learning" "platform ^ & FREE"
strsplit(x13,split='^',fixed=TRUE) [[1]] [1] "tutorialspoint " " is" [[2]] [1] "an " " E-learning" [[3]] [1] "platform " " & FREE"
Example
x14<-c("tutorialspoint ^is", "an ^E-learning", "platform & ^FREE") x14
Output
[1] "tutorialspoint ^is" "an ^E-learning" "platform & ^FREE"
strsplit(x14,split='^',fixed=TRUE) [[1]] [1] "tutorialspoint " "is" [[2]] [1] "an " "E-learning" [[3]] [1] "platform & " "FREE"
Example
x15<-c("tutorialspoint^is the best", "resource for^E-learning","in the^world") x15
Output
[1] "tutorialspoint^is the best" "resource for^E-learning" [3] "in the^world"
strsplit(x15,split='^',fixed=TRUE) [[1]] [1] "tutorialspoint" "is the best" [[2]] [1] "resource for" "E-learning" [[3]] [1] "in the" "world"
- Related Articles
- How to split a string vector that contain strings of equal sizes and have spaces between values then extract only few values in R?
- How to separate strings in R that are joined with special characters?
- How to filter rows that contain a certain string in R?
- How to count special characters in an R vector?
- Append special characters to column values in MySQL
- Check that the String does not contain certain characters in Java
- Filtering string to contain unique characters in JavaScript
- MySQL query to remove special characters from column values?
- How to extract the split string elements in R?
- Fetch a specific record from a column with string values (string, numbers and special characters) in MySQL
- Check if string contains special characters in Swift
- How to split comma separated values in an R vector?
- How to combine two vectors by separating with different special characters in R?
- How to remove rows that contain NAs in R matrix?
- MySQL regular expression to update a table with column values including string, numbers and special characters

Advertisements