Get Nth Character of a String
Get Nth Character of a String
Tags: String Manipulation Basics
Credit: CodingChallenge
Difficulty: Beginner
Type: Text
Category: Practice
Time Allowed: 5 s
Description:
Write a function that takes a string and a position (index) and returns the character at that position in the string. This problem is designed to help you practice string indexing
. The function should accept two parameters and return the character at the specified index.
Constraints:
- The input string will be a non-empty
string
. - The index will be a non-negative
integer
less than the length of the string. - The function should
return
astring
representing the character at the specified index.
Example:
- Input:
"hello", 1
- Output:
"e"
Test Case | Input | Expected Output |
---|---|---|
1 | ["hello", 1] | "e" |
2 | ["world", 0] | "w" |
3 | ["Python", 5] | "n" |
4 | ["OpenAI", 3] | "n" |
5 | ["ChatGPT", 6] | "T" |
6 | ["abcdef", 2] | "c" |
7 | ["string", 5] | "g" |
Leave a Comment
Please login to leave a comment.