If the response length is more than provided, I'm trying to obtain a substring from it and loop through it. My code is as follows:
string response = //response from API
if (response.Length > 4096)
{
for (int i = 0; i < response.Length; i += 4096)
{
string rplymsg = response.Substring(i, 4095);
//other code using rplymsg
}
}
else
{
//other code using response
}
I experimented with String. In debugging, the Substring method returns a substring of the provided length, but the real substring length is longer. (I double-checked this by pasting a substring into notepad++.)
I believe the issue is caused by the response string's substring rplymsg, which contains new lines n. Is there a better way to count the number of newlines in a string so that I may extract substrings based on that length?