Zhomfr.Helpers.ScalarTypes 0.2.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Zhomfr.Helpers.ScalarTypes --version 0.2.1
                    
NuGet\Install-Package Zhomfr.Helpers.ScalarTypes -Version 0.2.1
                    
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="Zhomfr.Helpers.ScalarTypes" Version="0.2.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Zhomfr.Helpers.ScalarTypes" Version="0.2.1" />
                    
Directory.Packages.props
<PackageReference Include="Zhomfr.Helpers.ScalarTypes" />
                    
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 Zhomfr.Helpers.ScalarTypes --version 0.2.1
                    
#r "nuget: Zhomfr.Helpers.ScalarTypes, 0.2.1"
                    
#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 Zhomfr.Helpers.ScalarTypes@0.2.1
                    
#: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=Zhomfr.Helpers.ScalarTypes&version=0.2.1
                    
Install as a Cake Addin
#tool nuget:?package=Zhomfr.Helpers.ScalarTypes&version=0.2.1
                    
Install as a Cake Tool

Helpers for scalar types

A collection of convenient and productive extension methods for some types in C# (string, decimal, IEnumerable), designed to simplify everyday data processing and formatting tasks.

📦 Installation

Install package:

dotnet add package Zhomfr.Helpers.ScalarTypes

After add namespace in using section:

using Zhomfr.Helpers.ScalarTypes;
using Zhomfr.Helpers.ScalarTypes.Strings;

Available Methods

String Methods

<table> <tr valign="top"> <td>

</td> <td>

</td> <td>

</td> </tr> </table>

Decimal Methods

<table> <tr valign="top"> <td>

</td> <td>

</td> <td>

</td> </tr> </table>

Enumerable Methods

<table> <tr valign="top"> <td>

</td> <td>

</td> <td>

</td> </tr> </table>

🛠️ Features and Examples

After

Returns everything after the given value in a string, or the entire string if the value is not found.

string value = "one/two/three";
string result = value.After("/"); // two/three

AfterLast

Returns everything after the last occurrence of the given value in a string, or the entire string if the value is not found.

string value = "one/two/three";
string result = value.AfterLast("/"); // three

Before

Returns everything before the given value in a string.

string value = "one/two/three";
string result = value.Before("/"); // one

BeforeLast

Returns everything before the last occurrence of the given value in a string.

string value = "one/two/three";
string result = value.BeforeLast("/"); // one/two

Between

Returns the portion of a string between two specified values.

string value = "[hello] [world]";
string result = value.Between("[", "]"); // hello] [world

BetweenFirst

Returns the smallest possible portion of a string between two specified values.

string value = "[hello] [world]";
string result = value.BetweenFirst("[", "]"); // hello

BetweenLast

Returns the last smallest possible portion of a string between two specified values.

string value = "[hello] [world]";
string result = value.BetweenLast("[", "]"); // world

CharAt

Returns the character at the specified index, or null if the index is out of bounds.

string value = "hello";
char? result = value.CharAt(1); // e

ChopEnd

Removes the first occurrence of any of the specified values from the end of the string.

string value = "example.com/";
            
string result1 = value.ChopEnd("/");      // example.com
string result2 = value.ChopEnd("/", "."); // example.com

ChopStart

Removes the first occurrence of any of the specified values from the start of the string.

string value = "https://example.com";
            
string result1 = value.ChopStart("https://");            // example.com
string result2 = value.ChopStart("https://", "http://"); // example.com

CountIsBetween

Determines whether the number of elements in the collection is within the specified range (inclusive).

public static class EnumerableStub
{
    public static IEnumerable GetValue()
    {
        yield return 1;
        yield return 2;
        yield return 3;
    }
}
            
EnumerableStub.GetValue().CountIsBetween(1,3) // true
EnumerableStub.GetValue().CountIsGreatThan(3,5) // true
EnumerableStub.GetValue().CountIsGreatThan(4,6) // false
EnumerableStub.GetValue().CountIsGreatThan(1,2) // false

CountIsGreatThan

Determines whether the number of elements in the collection is greater than the specified minimum value.

public static class EnumerableStub
{
    public static IEnumerable GetValue()
    {
        yield return 1;
        yield return 2;
        yield return 3;
    }
}
            
EnumerableStub.GetValue().CountIsGreatThan(2) // true
EnumerableStub.GetValue().CountIsGreatThan(3) // false
EnumerableStub.GetValue().CountIsGreatThan(4) // false

CountIsGreatThanOrEqual

Determines whether the number of elements in the collection is greater than or equal to the specified minimum value.

public static class EnumerableStub
{
    public static IEnumerable GetValue()
    {
        yield return 1;
        yield return 2;
        yield return 3;
    }
}
            
EnumerableStub.GetValue().CountIsGreatThanOrEqual(2) // true
EnumerableStub.GetValue().CountIsGreatThanOrEqual(3) // true
EnumerableStub.GetValue().CountIsGreatThanOrEqual(4) // false

CountIsLessThan

Determines whether the number of elements in the collection is less than the specified maximum value.

public static class EnumerableStub
{
    public static IEnumerable GetValue()
    {
        yield return 1;
        yield return 2;
        yield return 3;
    }
}
            
EnumerableStub.GetValue().CountIsLessThan(2) // false
EnumerableStub.GetValue().CountIsLessThan(3) // false
EnumerableStub.GetValue().CountIsLessThan(4) // true

CountIsLessThanOrEqual

Determines whether the number of elements in the collection is less than or equal to the specified maximum value.

public static class EnumerableStub
{
    public static IEnumerable GetValue()
    {
        yield return 1;
        yield return 2;
        yield return 3;
    }
}
            
EnumerableStub.GetValue().CountIsLessThanOrEqual(2) // false
EnumerableStub.GetValue().CountIsLessThanOrEqual(3) // true
EnumerableStub.GetValue().CountIsLessThanOrEqual(4) // true

Deduplicate

Replaces consecutive instances of the specified substring with a single instance in the string. By default, deduplicates spaces.

string value = "hello   world";
            
string result = value.Deduplicate(); // hello world

EndWith

Ends the string with a single instance of the specified value if it does not already end with it.

string value = "example";
            
 string result = value.EndWith(".com"); // example.com

Excerpt

Extracts an excerpt from the string that matches the first instance of the specified phrase.

string value = "The quick brown fox jumps over the lazy dog";
            
string result = value.Excerpt("fox", radius: 5); // ...own fox jump...

FromBase64

Decodes the given Base64 string, or returns null if the string is not a valid Base64 encoding.

string value = "SGVsbG8=";
            
string result = value.FromBase64(); // Hello

GetDecimal

Gets the number of digits after the decimal separator.

decimal value = 123.45m;
int result = value.GetDigits(); // 5

GetDigits

Gets the total number of digits before and after the decimal separator.

decimal value = 123.45m;
int result = value.GetDigits(); // 5

GetDigitsBeforeSeparator

Gets the number of digits in the integer part of the decimal value.

decimal value = 123.45m;
int result = value.GetDigitsBeforeSeparator(); // 3

Initials

Returns the initials of the string, optionally capitalizing them.

string value = "John Ronald Reuel Tolkien";
string result = value.Initials(); // JRRT

LcFirst

Returns the string with its first character converted to lowercase.

string value = "HELLO";
            
 string result = value.LcFirst(); // hELLO

Limit

Truncates the string to the specified length, optionally appending a custom string to the end of the truncated result. Can preserve complete words at the nearest word boundary when specified.

string value = "The quick brown fox";
string result = value.Limit(12); // The quick ...

Mask

Masks a portion of a string with a repeated character, which can be used to obfuscate segments of sensitive strings such as email addresses and phone numbers.

string value = "john@example.com";
string result = value.Mask(4, 4); // john*********e.com

PadBoth

Pads both sides of a string with another string until the final string reaches the specified length.

string value = "title";
string result = value.PadBoth(9, "-"); // --title--

Remove

Removes the specified values from the string in a case-sensitive manner.

string value = "a-b-c";
string result = value.Remove("-"); // abc

RemoveIgnoreCase

Removes the specified values from the string in a case-insensitive manner.

string value = "Hello HELLO World";
string result = value.RemoveIgnoreCase("hello"); // World

Replace

Replaces a given value in the string sequentially using an array of replacement values.

string value = "a-b-c";
string result = value.Replace("-", ["1", "2"]); // a1b2c

ReplaceFirst

Replaces the first occurrence of a specified string with another string, with an option to control case sensitivity.

string value = "foo foo";
string result = value.ReplaceFirst("foo", "bar"); // bar foo

ReplaceLast

Replaces the last occurrence of a specified string with another string, with an option to control case sensitivity.

string value = "foo foo";
string result = value.ReplaceLast("foo", "bar"); // foo bar

ReplaceMatches

Replaces all portions of a string matching a regular expression pattern with the specified replacement string.

string value = "foo123 bar456";
string result = value.ReplaceMatches(@"\d+", "#"); // foo# bar#

Reverse

Reverses the given string.

string value = "hello";
string result = value.Reverse(); // olleh

Squish

Removes all extraneous white space from the string, including extra white space between words.

string value = "  hello   world  ";
string result = value.Squish(); // hello world

StartWith

Begins the string with a single instance of the specified value if it does not already start with it.

string value = "example.com";
string result = value.StartWith("https://"); // https://example.com

SubstringCount

Returns the number of occurrences of a given value in the string.

string value = "one two one";
int result = value.SubstringCount("one"); // 2

SubstringReplace

Replaces text within a portion of a string, starting at the specified position and replacing the number of characters specified by the length. Passing 0 for the length inserts the string without replacing any existing characters.

string value = "hello world";
string result = value.SubstringReplace("C#", 6, 5); // hello C#

Swap

Replaces multiple values in the string.

string value = "hello world";
string result = value.Swap(new() { ["hello"] = "hi", ["world"] = "there" }); // hi there

ToBase64

Converts the given string to its Base64-encoded representation.

string value = "Hello";
string result = value.ToBase64(); // SGVsbG8=

ToCamelCase

Converts the given string to camelCase.

string value = "hello_world";
string result = value.ToCamelCase(); // helloWorld

ToKebabCase

Converts the string to kebab-case.

string value = "hello world";
string result = value.ToKebabCase(); // hello-world

ToPascalCase

Converts the given string to PascalCase.

string value = "hello world";
string result = value.ToKebabCase(); // hello-world

ToSnakeCase

Converts the given string to snake_case.

string value = "helloWorld";
string result = value.ToSnakeCase(); // hello_world

UcFirst

Capitalizes the first character of the given string.

string value = "hello";
string result = value.UcFirst(); // Hello

UcSplit

Splits the string into a list by uppercase characters.

string value = "hello";
string result = value.UcFirst(); // Hello

UcWord

Converts the first character of each word in the given string to uppercase.

string value = "hello world";
string result = value.UcWord(); // Hello World

WordCount

Returns the number of words that the string contains.

string value = "hello world";
int result = value.WordCount(); // 2
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Zhomfr.Helpers.ScalarTypes:

Package Downloads
Zhomfr.Validation.Rules

A powerful, intuitive collection of custom validation attributes built directly on top of the standard .NET System.ComponentModel.DataAnnotations infrastructure.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.7.1 295 11/7/2026
0.7.0 277 10/26/2026
0.6.0 137 10/24/2026
0.5.0 111 10/23/2026
0.4.1 115 10/23/2026
0.4.0 121 10/22/2026
0.3.0 116 10/22/2026
0.2.1 120 10/21/2026
0.2.0 111 10/21/2026
0.1.0 138 8/15/2026