From eedb1a238be11fa87a36a6eede6aecb5997d3232 Mon Sep 17 00:00:00 2001 From: Gary Holland Date: Mon, 14 Dec 2020 20:57:52 +1100 Subject: [PATCH] added split reverse function --- src/dexih.functions.builtIn/MapFunctions.cs | 22 +++++++++++++++++++-- src/dexih.transforms/Table/TableColumn.cs | 7 ++++++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/dexih.functions.builtIn/MapFunctions.cs b/src/dexih.functions.builtIn/MapFunctions.cs index d1a557d3..224a9701 100644 --- a/src/dexih.functions.builtIn/MapFunctions.cs +++ b/src/dexih.functions.builtIn/MapFunctions.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text.RegularExpressions; using System.Xml; @@ -96,7 +97,7 @@ public string Replace(string value, string oldValue, string newValue) } [TransformFunction(FunctionType = EFunctionType.Map, Category = "String", Name = "Split", - Description = "Splits a string into multiple return fields that are based on the characters in an array.")] + Description = "Splits a string into multiple return fields using the separator as the delimiter")] public int Split(string value, string separator, int? count, out string[] result) { if (string.IsNullOrEmpty(value) || string.IsNullOrEmpty(separator)) @@ -110,6 +111,22 @@ public int Split(string value, string separator, int? count, out string[] result return result.Length; } + [TransformFunction(FunctionType = EFunctionType.Map, Category = "String", Name = "Split Reverse", + Description = "Splits a string into multiple return fields (in reverse) using the separator as the delimiter")] + public int SplitReverse(string value, string separator, out string[] result) + { + if (string.IsNullOrEmpty(value) || string.IsNullOrEmpty(separator)) + { + result = null; + return 0; + } + + result = value.Split(separator.ToCharArray()).Reverse().ToArray(); + + return result.Length; + } + + [TransformFunction(FunctionType = EFunctionType.Map, Category = "String", Name = "Substring", Description = "Retrieves a substring from this instance. The substring starts at a specified character position and has a specified length.")] @@ -478,7 +495,8 @@ public T Switch(object value, [TransformFunctionLinkedParameter("When")] obje return defaultValue; } - + + } } diff --git a/src/dexih.transforms/Table/TableColumn.cs b/src/dexih.transforms/Table/TableColumn.cs index c8cc6fce..75ac3d77 100644 --- a/src/dexih.transforms/Table/TableColumn.cs +++ b/src/dexih.transforms/Table/TableColumn.cs @@ -383,7 +383,12 @@ public void ResetFormat(bool force = false) case ETypeCode.UInt16: case ETypeCode.UInt32: case ETypeCode.UInt64: - Format = "#,##0"; + // if the column is a tracking or non-tracking field, it is likely to be a value which should be formatted with commas. + if (DeltaType == EDeltaType.TrackingField || DeltaType == EDeltaType.NonTrackingField) + { + Format = "#,##0"; + } + break; case ETypeCode.Single: case ETypeCode.Decimal: