.Length returns the total length of the string starting from 1. We need to access the index which begins at 0. If we wanted to access the last index of the original string it would be Length-1. Since we want to cut the last character off, we use -2. Hope that helps
The solution is taking a substring starting from the second character and a number of charachers after that equal to the length of the full string minus two.
Example:
12345
You want 234, which is three characters long. You tell it to skip the first character and then take the three characters after the first one. Therefore it is the length of the full string minus two.
I understand that this solution is 100% correct, but I don't understand why we subtract s.Length by 2 instead of 1, wouldn't subtracting by 2 remove the last two characters instead of just the last character? ChatGPT kept talking in circles and broke trying to clarify this for me.
@mmangiamusardo please mark your post as having spoiler content next time.
This comment is hidden because it contains spoiler information about the solution
.Length returns the total length of the string starting from 1. We need to access the index which begins at 0. If we wanted to access the last index of the original string it would be Length-1. Since we want to cut the last character off, we use -2. Hope that helps
Had a hard time with this one, because i really wanted to use the replace()-method. But in this case it's kinda "worst" practise.^^
The first character is the other of the two.
The solution is taking a substring starting from the second character and a number of charachers after that equal to the length of the full string minus two.
Example:
You want
234
, which is three characters long. You tell it to skip the first character and then take the three characters after the first one. Therefore it is the length of the full string minus two.I understand that this solution is 100% correct, but I don't understand why we subtract s.Length by 2 instead of 1, wouldn't subtracting by 2 remove the last two characters instead of just the last character? ChatGPT kept talking in circles and broke trying to clarify this for me.
This comment is hidden because it contains spoiler information about the solution