From 442a967cd98fb11bd1f29d00caa217af302b29cb Mon Sep 17 00:00:00 2001 From: Brychan Dempsey Date: Wed, 24 Mar 2021 15:35:56 +1300 Subject: [PATCH] Fixed an issue with a character being dropped in GetStringLines() --- Assignment 1/Program.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Assignment 1/Program.cs b/Assignment 1/Program.cs index 052e0a8..2a1c538 100644 --- a/Assignment 1/Program.cs +++ b/Assignment 1/Program.cs @@ -896,11 +896,12 @@ namespace Assignment_1 static List GetStringLines(string source, int maxWidth) { List lines = new(); - for (int i = 0; i < source.Length; i++) + int j = 0; + while (j < source.Length) { - int max = i + maxWidth <= source.Length ? i + maxWidth : source.Length; - lines.Add(source[i..max]); - i = max; + int max = j + maxWidth <= source.Length ? j + maxWidth : source.Length; + lines.Add(source[j..max]); + j = max; } return lines; }