Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

r
string
size
communitycreator

How to calculate the size of a string using nchar() in R

harris910

The nchar() function in R is used to calculate the size of a string.

The illustration below shows the mathematical representation of the nchar() function.

Visual representation of nchar() function

Syntax

nchar(string)

Parameter

The nchar() function requires a string as a parameter.

Return value

This function returns the size of a string.

Code

a <- nchar("hello");
print(paste0("nchar('hello): ", a))

b <- nchar("educative");
print(paste0("nchar('educative): ", b))

RELATED TAGS

r
string
size
communitycreator
RELATED COURSES

View all Courses

Keep Exploring