Regular expression – check if there is only space in the string

How to check if there are only spaces in a string?

I want to use conditions in an if() statement.

For example,

str<-" "< br />#check if str has only white spaces? example usage 
if(str != empty)...

You can use trimws to remove leading/trailing spaces from the string:

trimws(str) == ""
#[1] TRUE

How to check if there are only spaces in the string?

I want to use conditions in an if() statement.

For example,

str<-" "< br />#check if str has only white spaces? example usage 
if(str != empty)...

You can use trimws ,Remove leading/trailing spaces from the string:

trimws(str) == ""
#[1] TRUE

< /p>

Leave a Comment

Your email address will not be published.