주어진 단어 뒤에 문자열을 가져 오려고합니다. 아래는 코드입니다.string.Length가 text.Substring에서 작동하지 않는 이유는 무엇입니까?
private static string GetStringAfterWord(string text, int position)
{
if (text.Length - 1 < position || text[position] == ' ') return null;
int start = position;
int end = position;
while (end < text.Length - 1)
end++;
return text.Substring(start, end);
}
이 코드는 항상 날이 오류를 줄 : System.ArgumentOutOfRangeException이를 : 인덱스 및 길이는 문자열 내의 위치를 참조해야합니다.
string.Length가 총 문자 수를 반환하지 않으며 항상 범위를 벗어나는 이유는 무엇입니까? 내가 잘못 했니?