When I want to do a substring to find a region of text in a string in Java, I will put two indexes: one for start and one for end , but in C # I force the substring length to be provided as a parameter, however this becomes a problem if I don't know where should I stop, which will lead me to the following things:
verse[i].Substring(verse[i].IndexOf("start"), (verse[i].IndexOf("end") - verse[i].IndexOf("start"));
instead
verse[i].Substring(verse[i].IndexOf("start"), (verse[i].IndexOf("end"));
Annoyingly, I have come across this problem over and over again and I am wondering if I am the only one or is there a trick I don’t know about. How could you solve this problem best? (Considering cleanliness and speed)
ps: I don't like creating variables for almost anything. Thanks
source share