Trim empty entries in string split calls

This commit is contained in:
Slendy 2023-02-11 21:12:10 -06:00
commit e93aea1977
No known key found for this signature in database
GPG key ID: 7288D68361B91428
3 changed files with 4 additions and 5 deletions

View file

@ -57,9 +57,7 @@
} }
else else
{ {
authorLabels = Model.Slot?.AuthorLabels.Split(",") ?? Array.Empty<string>(); authorLabels = Model.Slot?.AuthorLabels.Split(",", StringSplitOptions.RemoveEmptyEntries) ?? Array.Empty<string>();
// Split() returns an array with an empty character for some reason
if (authorLabels.Length == 1) authorLabels = Array.Empty<string>();
} }
if (authorLabels.Length == 0) if (authorLabels.Length == 0)
{ {

View file

@ -10,7 +10,7 @@ public class ConsoleLogger : ILogger
ConsoleColor oldForegroundColor = Console.ForegroundColor; ConsoleColor oldForegroundColor = Console.ForegroundColor;
ConsoleColor logColor = logLine.Level.ToColor(); ConsoleColor logColor = logLine.Level.ToColor();
foreach (string line in logLine.Message.Split('\n')) foreach (string line in logLine.Message.Split('\n', StringSplitOptions.RemoveEmptyEntries))
{ {
string time = DateTime.Now.ToString("MM/dd/yyyy-HH:mm:ss.fff"); string time = DateTime.Now.ToString("MM/dd/yyyy-HH:mm:ss.fff");
string trace = ""; string trace = "";

View file

@ -1,4 +1,5 @@
#nullable enable #nullable enable
using System;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using System.Xml.Serialization; using System.Xml.Serialization;
@ -38,7 +39,7 @@ public class Review
[NotMapped] [NotMapped]
[XmlIgnore] [XmlIgnore]
public string[] Labels { public string[] Labels {
get => this.LabelCollection.Split(","); get => this.LabelCollection.Split(",", StringSplitOptions.RemoveEmptyEntries);
set => this.LabelCollection = string.Join(',', value); set => this.LabelCollection = string.Join(',', value);
} }