VOOZH about

URL: https://www.geeksforgeeks.org/dsa/find-the-length-of-a-string/

⇱ Length of a String - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Length of a String

Last Updated : 23 Jul, 2025

Given a string s, the task is to find the length of the string.

Examples:

Input: s = "abc"
Output: 3

Input: s = "GeeksforGeeks"
Output: 13

Input: s = ""
Output: 0

Using In-built methods

Every programming language offers a built-in method as well to find the length


Output
3

Programming Language

In-Built method to find the length of the string

C

strlen()

C++

size()

Java

length()

Python

len()

JavaScript

length

C#

length()

Writing your Method

The most traditional method of finding the length of the string is by traversing each character through the loop.

  • Using a counter, traverse each character of the string with the help of Loop.
  • Return the counter value as the length of the string.

Output
13

Time Complexity: O(n), where n is the length of the string.
Auxiliary space: O(1)

Comment
Article Tags:
Article Tags: