From 4553e42a1151ad113ad6f534854d2926e28fa74c Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Sat, 5 May 2018 17:13:12 +0200 Subject: [PATCH] Whitespace fix --- Logic/Financial/ExternalBankData.cs | 6 ++++-- Logic/Support/ExtensionMethods.cs | 11 +++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Logic/Financial/ExternalBankData.cs b/Logic/Financial/ExternalBankData.cs index 9797b3f8..f3b8920f 100644 --- a/Logic/Financial/ExternalBankData.cs +++ b/Logic/Financial/ExternalBankData.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Globalization; using System.IO; using System.Security.Cryptography; +using System.Web.ExtensionMethods; using Swarmops.Common; using Swarmops.Logic.Structure; using Swarmops.Logic.Support; @@ -407,9 +408,10 @@ namespace Swarmops.Logic.Financial } - // remove all known noise from the digit sequence: spaces, thousands accents, commas, periods + // remove all known noise from the digit sequence: all whitespace, thousands accents, commas, periods - input = input.Replace (" ", "").Replace ("'", "").Replace (",", "").Replace (".", ""); + input = input.RemoveAllWhitespace(); + input = input.Replace ("'", "").Replace (",", "").Replace (".", ""); // parse what's remaining as cents in Int64 diff --git a/Logic/Support/ExtensionMethods.cs b/Logic/Support/ExtensionMethods.cs index e229f294..4fcef013 100644 --- a/Logic/Support/ExtensionMethods.cs +++ b/Logic/Support/ExtensionMethods.cs @@ -1,5 +1,6 @@ using System.Globalization; using System.IO; +using System.Linq; namespace System.Web.ExtensionMethods { @@ -91,4 +92,14 @@ namespace System.Web.ExtensionMethods } } } + + public static class StringExtensions + { + public static string RemoveAllWhitespace(this string input) + { + return new string(input.ToCharArray() + .Where(c => !Char.IsWhiteSpace(c)) + .ToArray()); + } + } } \ No newline at end of file