C#C
C#2y ago
3 replies
itsnotabbas

Trailing whitespace problem

I'm doing a codewars problem, and i keep getting this error but i dont know how to fix it. Any help? Thanks

using System;
using System.Linq;
using System.Text.RegularExpressions;
public class StripCommentsSolution
{
    public static string StripComments(string text, string[] symbols)
    {
      
      string[] lines = text.Split(new string[] { "\n" }, StringSplitOptions.None);


      string newStr = "";

      foreach (var line in lines)
      {
          int index = -1;
          foreach (var letter in line)
          {
              if (symbols.Contains(letter.ToString()))
              {
                  index = line.IndexOf(letter.ToString());

                  newStr += line.Substring(0, index).TrimEnd() + "\n";

                  break;
              }
          }
          if (index == -1)
          {
              newStr += line.TrimEnd() + "\n";
          }
      }
      
      newStr = newStr.TrimEnd();
      
      return newStr;
    }
}
Was this page helpful?