Extract Substring

You are given a string str, and two integers pos (0-base indexing) and len.

  • Extract a substring starting at index pos with length len.
  • Return the extracted substring.

Example 1:

Input: str = "Hello", pos = 1, len = 3

Output: ell

Example 2:

Input: str = "welcome", pos = 4, len = 1

Output: o

Now Your Turn!

Pick the correct output for the given input

Input: str = "welcomeToTUF+", pos = 9, len = 4

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 0 ≤ pos < length of string
  • 0 ≤ len ≤ 100
  • String length ≤ 100
  • pos + len <= String length
  • String may contain: lowercase letters, uppercase letters, digits, special characters

Hints

0
class Solution {
public:
string getSubstring(string str, int pos, int len) {
//your code goes here
}
};
Test Case

Input:

Len
Pos
Str