I'm aware that there is a resource here on this site; however, I'm struggling to understand this following problem from the book!To start it off, I have a string function inilized as string sentence="It is cloudy and warm."
Im struggling to understand how the following functions listed below will give you those output.
sentence.subst(6,6) would give you
sentence.subst(6,16) would give you
cloudy and warm
Generally speaking, can someone explain to me in an intermediate way. I'm a really slow learner and tend to do better when things are explained to me one by one. Also there was one other function sentence.subst(0,5) I know the outcome for that should be [output]It is[/output. I inrepreted that function as starting from position 0 and ending at position 5. After position 5, it discards the rest of the string.
Besides this, sentence.subst(1,5) when I'm looking for the postion (1), from "It is cloudy and warm.." Would position start from 0 or 1 here. In other words would 1 be "I" or "T".
The first parameter is a start position, which is 0 based.
Second parameter defines how many characters to be extracted/returned from the start position.
So sentence.subst(6,6) would start at 6th position where position is zero based that mean it will start from 7th character. So it will start from "c" of cloudy. and it will get 6 characters from c, which is "cloudy".
For sentence.subst(6,16) would start at 6th position where position is 0 based. So it will start from "c" of cloudy. and it will get 16 characters from c, which is "cloudy and warm".
To answer your last question, position parameter is zero based. "I" is at position 0. "t" is at position 1. So position 1 would be "t" and subst(1,5) would return you "t is "