Skip to content
Related Articles

Related Articles

Finding the length of string in R programming – nchar() method
  • Last Updated : 10 May, 2020

nchar() method in R programming is used to get the length of a string.

Syntax: nchar(string)

Return: Returns the length of a string.

Example 1:




# R program to calculate length of string
  
# Given String
gfg <- "Geeks For Geeks"
  
# Using nchar() method
answer <- nchar(gfg)
  
print(answer)

Output:

[1] 15

Example 2:




# R program to calculate length of string
  
# Given String
gfg <- "The quick brown fox jumps over the lazy dog"
  
# Using nchar() method
answer <- nchar(gfg)
  
print(answer)

Output:

[1] 43
My Personal Notes arrow_drop_up
Recommended Articles
Page :