Complete the code to access the first character of the string.
char firstChar = str[1];In many programming languages, strings can be treated like arrays of characters. To access the first character, you use square brackets with index 0.
Complete the code to get the length of the string.
int length = str[1];.size() which may work in some languages but not all..count() which counts occurrences of a character.The .length() method returns the number of characters in a string.
Fix the error in accessing the last character of the string.
char lastChar = str[1];str.length() as index which is out of bounds.Since string indices start at 0, the last character is at index length - 1.
Fill both blanks to create a substring from index 2 to 5.
String sub = str[1]([2], 4);
The .substr(start, length) method extracts a part of the string starting at index start with the given length.
Fill all three blanks to create a dictionary of characters and their counts from the string.
charCount = [1](c: str[[2]] for [3] in range(len(str)))
This code creates a dictionary where each character from the string is a key. It uses a loop variable i to access each character by index.