FluentCoding.String 2.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package FluentCoding.String --version 2.0.0
                    
NuGet\Install-Package FluentCoding.String -Version 2.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="FluentCoding.String" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FluentCoding.String" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="FluentCoding.String" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add FluentCoding.String --version 2.0.0
                    
#r "nuget: FluentCoding.String, 2.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package FluentCoding.String@2.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=FluentCoding.String&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=FluentCoding.String&version=2.0.0
                    
Install as a Cake Tool

FluentCoding.String

Add a set of functionalities to manipulate strings

PrependWhen

Allow to prepend ad item into a IEnumerable<string> when the predicate is satisfied

var IEnumerable<string> BuildCsvHeader() { /* do something  [...]*/ return csvHeader; }
var IEnumerable<string> BuildCsvContent() { /* do something  [...]*/ return csvContent; }

var IEnumerable<string> BuildCsv(bool includeHeader)
{
    BuildCsvContent()
    .PrependWhen(BuildCsvHeader(), includeHeader)
}

var IEnumerable<string> BuildCsv(bool includeHeader, int currentFileNumber)
{
    BuildCsvContent()
    .PrependWhen(BuildCsvHeader(), () => currentFileNumber > 1)
}

Concatenate

Add a small set of tools to concatanate string with a bit of logic. For all the following methods the concatenation is enabled only when the base value is not null or default

By default the option used to check the input validity is: StringIsNullWhenEnum.NullOrEmpty

ConcatLeftToAll, ConcatRightToAll

Take an IEnumerable<string> ad append to each item the input string

List<string> domainValues = new List<string>() {"left1-","left2-","left3-"}
var result = "rightValue".ConcatRightToAll(domainValues);
//result => {"left1-rightValue","left2-rightValue","left3-rightValue"}
 internal static string ToCsv(this XElement node, string csvChar) => { /* do something [...]*/ return csvNode;}
 
 internal static string MainNodeToCsv(this XElement rootElement, string csvChar) =>
    rootElement.DescendantsAndSelf("Main").First().ToCsv(csvChar)

 static IEnumerable<string> BuildCsv(XElement rootElement, string csvChar, bool includeHeader, string externalReference) =>
    string.Join(csvChar, externalReference, rootElement.MainNodeToCsv(csvChar))
          .ConcatLeftToAll(rootElement.ContentNodesToCsv(csvChar), csvChar)
          .PrependWhen(GetCsvHeader(csvChar), () => includeHeader);
List<string> coordinates = new List<string> ("33.21338, 2.71403", "", "7.40338, 22.10301")
var coordinateDescriptions = coordinates.ConcatLeftToAll("Decimal degrees (DD)", " -> ");
/* result:
coordinateDescriptions:
{
    "Decimal degrees (DD) -> 33.21338, 2.71403", 
    "", 
    "Decimal degrees (DD) -> 7.40338, 22.10301"
}
*/

ConcatRightTo, ConcatLeftTo

Join an input string with the specified value, when the input is not null or default By default the option used to check the input validity is: StringIsNullWhenEnum.NullOrEmpty

"left".ConcatLeftTo("-right"); // -> "left-right"
" ".ConcatLeftTo("-right"); // -> " -right"
" ".ConcatLeftTo("-right", StringIsNullWhenEnum.NullOrEmptyOrWhiteSpaces); // -> ""
"".ConcatLeftTo("right"); // -> ""
"".ConcatLeftTo("right", StringIsNullWhenEnum.Null); // -> "-right"
null.ConcatLeftTo("right"); // -> ""
 //Create the address only when the base info 'street-name' is available
 public string GetFullAddress(XPathNavigator addressXmlSource) =>
     addressXmlSource.GetAttribute("street-name")
        .ConcatLeftTo(addressXmlSource.GetAttribute("street-number"))
        .ConcatLeftTo(addressXmlSource.GetAttribute("province"));

ConcatWhenWithValue

Join an input string with a left and right string when the input has value

"center".ConcatWhenWithValue("left-", "-right"); //left-center-right
" ".ConcatWhenWithValue("-right"); //left- -right
" ".ConcatWhenWithValue("-right", StringIsNullWhenEnum.NullOrEmptyOrWhiteSpaces); // -> ""
"".ConcatWhenWithValue("right"); // -> ""
"".ConcatWhenWithValue("right", StringIsNullWhenEnum.Null); // -> "left--right"
null.ConcatWhenWithValue("right"); // -> ""
 //Create the province description only when the provice is available: 
 //Example: 
 //output can be: "Bologna (BO)" or "Bologna" 
 //but not "Bologna ()" or "()"
 public string GetFullAddress(XPathNavigator addressXmlSource) =>
     addressXmlSource.GetAttribute("province-name")
        .ConcatLeftTo(
            addressXmlSource.GetAttribute("province-name-short")
            .ConcatWhenWithValue("(", ")")
        );
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 is compatible.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.1.3 752 4/3/2023
2.1.1 367 3/16/2023
2.1.0 379 2/24/2023
2.0.0 431 1/11/2023
1.2.1 412 1/5/2023
1.2.0 425 1/5/2023
1.1.0 413 1/3/2023
1.0.4 420 1/2/2023
1.0.0 421 1/2/2023

Updated with latest FluentCoding changes
Reworked null management with StringIsNullWhenEnum
Null check applied only on the subject, the append values are used as provided