VOOZH about

URL: https://www.nuget.org/packages/CaseConverter/

โ‡ฑ NuGet Gallery | CaseConverter 2.0.1


๏ปฟ

CaseConverter 2.0.1

dotnet add package CaseConverter --version 2.0.1
 
 
NuGet\Install-Package CaseConverter -Version 2.0.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="CaseConverter" Version="2.0.1" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CaseConverter" Version="2.0.1" />
 
Directory.Packages.props
<PackageReference Include="CaseConverter" />
 
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 CaseConverter --version 2.0.1
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: CaseConverter, 2.0.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 CaseConverter@2.0.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=CaseConverter&version=2.0.1
 
Install as a Cake Addin
#tool nuget:?package=CaseConverter&version=2.0.1
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Case Converter for .NET ๐Ÿ‘ Build status
๐Ÿ‘ AppVeyor tests
๐Ÿ‘ GitHub
๐Ÿ‘ GitHub

โ€œNaming Conventions is one of the two hard things in Computer Scienceโ€ --- Jeff Atwood (Stack Overflow Co-founder).

This library is designed to make it easier to convert the different case conventions in c# / .net through some simple to use string extension methods.

Simple string extension library designed to make it easy to convert strings between different cases such as camelCase, snake_case, kebab-case, PascalCase, Train-Case and Title Case.

This is a .NET STANDARD 2.0 and .NET STANDARD 2.1 Library

Installation

NuGet:

Install-Package CaseConverter

dotnet CLI

dotnet add package CaseConverter

Usage

	
 using CaseConverter;

 Console.WriteLine("Hello World!".ToCamelCase());
 Console.WriteLine("Hello World!".ToSnakeCase());
 Console.WriteLine("Hello World!".ToKebabCase());
 Console.WriteLine("Hello World!".ToPascalCase());
 Console.WriteLine("Hello World!".ToTitleCase());
 Console.WriteLine("Hello World!".ToTrainCase());
 

String extensions:

  • string.ToSnakeCase() Converts any string to snake_case.
  • string.ToCamelCase() Converts any string to camelCase optionally removing whitespace.
  • string.ToKebabCase() Converts any string to kebab-case.
  • string.ToPascalCase() Converts any string to PascalCase.
  • string.ToTrainCase() Converts any string to Train-Case.
  • string.ToTitleCase() Converts any string to Title Case. Wrapper for TextInfo.ToTitleCase()

Supplementary string extensions included:

  • string.PascalCaseSingleWord() Convert a single word to Pascal Case.
  • string.InsertCharacterBeforeUpperCase() Insert any character before all upper space characters in a string.
  • string.InsertSpaceBeforeUpperCase() Insert a space before all upper space characters in a string.
  • string.SplitCamelCase() Split a string by Uppercase whilst dealing correctly with acronyms.
  • string.Replace() Replace specific characters found in a string.
  • string.ReplaceWhitespace() C Replace all whitespace in a string.
  • string.InsertCharacterBeforeUpperCase() Converts a string to Title Case.
  • string.IsAllUpper() Test to determine if a string is all upper case.
  • string.SnakeCaseToCamelCase() Convert SnakeCase to CamelCase.
  • string.FirstCharToLowerCase() Convert the first character in a string to lower case.
  • string.FirstCharToUpperCase() Convert the first character in a string to upper case.

Tests

We added a lot more tests in the latest version.

To run tests:

dotnet test

Benchmarks

For the latest version we're working on improving performance and memory efficiency.. here is a comparison of the improvements.

Additional gains will likely be possible if also target .net 6+. So far we've only done that with ToTitleCase() but we'll update the other methods soon.

ToPascalCase()
Method Mean Error StdDev Gen0 Allocated
ToPascalCaseBenchmark 179.9 ns 3.00 ns 2.34 ns 0.0315 264 B
ToPascalCaseBenchmarkOld 2,269.5 ns 43.25 ns 36.12 ns 0.4005 3352 B
ToKebabCase()
Method Mean Error StdDev Gen0 Allocated
ToKebabCaseBenchmark 132.1 ns 2.69 ns 4.02 ns 0.0324 272 B
ToKebabCaseBenchmarkOld 1,423.1 ns 27.69 ns 27.19 ns 0.0496 424 B
ToTitleCase()
Method Mean Error StdDev Gen0 Allocated
ToTitleCaseBenchmark 218.3 ns 2.59 ns 2.43 ns 0.0200 168 B
ToTitleCaseBenchmarkOld 225.8 ns 3.26 ns 3.05 ns 0.0381 320 B
ToCamelCase()
Method Mean Error StdDev Gen0 Allocated
ToCamelCaseBenchmark 1.497 us 0.0206 us 0.0193 us 0.1659 1.36 KB
ToCamelCaseOldBenchmark 5.362 us 0.0730 us 0.0609 us 0.4272 3.52 KB
ToSnakeCase()

Wasn't able to improve it so left the original code intact.

Method Mean Error StdDev Gen0 Allocated
ToSnakeCaseBenchmark 1.765 us 0.0112 us 0.0094 us 0.1793 1.47 KB
All Tests
Method Job Runtime Mean Error StdDev Ratio RatioSD Gen0 Allocated Alloc Ratio
ToSnakeCaseBenchmark .NET 5.0 .NET 5.0 199.257 ns 3.8065 ns 3.9090 ns 0.95 0.02 0.0343 288 B 1.00
ToSnakeCaseBenchmark .NET 6.0 .NET 6.0 177.983 ns 3.4400 ns 3.6807 ns 0.84 0.02 0.0343 288 B 1.00
ToSnakeCaseBenchmark .NET 7.0 .NET 7.0 164.851 ns 1.4823 ns 1.3140 ns 0.78 0.01 0.0343 288 B 1.00
ToSnakeCaseBenchmark .NET Core 3.1 .NET Core 3.1 211.328 ns 2.4708 ns 2.0633 ns 1.00 0.00 0.0343 288 B 1.00
ToCamelCaseBenchmark .NET 5.0 .NET 5.0 115.336 ns 2.3167 ns 2.2753 ns 0.77 0.05 0.0200 168 B 1.00
ToCamelCaseBenchmark .NET 6.0 .NET 6.0 82.941 ns 1.4910 ns 1.3946 ns 0.56 0.03 0.0200 168 B 1.00
ToCamelCaseBenchmark .NET 7.0 .NET 7.0 86.708 ns 1.3273 ns 1.0363 ns 0.58 0.03 0.0200 168 B 1.00
ToCamelCaseBenchmark .NET Core 3.1 .NET Core 3.1 156.865 ns 3.6809 ns 10.8532 ns 1.00 0.00 0.0200 168 B 1.00
ToKebabCaseBenchmark .NET 5.0 .NET 5.0 188.836 ns 2.3753 ns 2.1056 ns 0.89 0.03 0.0324 272 B 1.00
ToKebabCaseBenchmark .NET 6.0 .NET 6.0 129.301 ns 1.7678 ns 1.5671 ns 0.61 0.02 0.0324 272 B 1.00
ToKebabCaseBenchmark .NET 7.0 .NET 7.0 127.751 ns 2.3711 ns 2.2179 ns 0.60 0.02 0.0324 272 B 1.00
ToKebabCaseBenchmark .NET Core 3.1 .NET Core 3.1 210.257 ns 4.2073 ns 6.0339 ns 1.00 0.00 0.0324 272 B 1.00
ToPascalCaseBenchmark .NET 5.0 .NET 5.0 278.123 ns 3.2519 ns 3.0418 ns 0.85 0.02 0.0315 264 B 1.00
ToPascalCaseBenchmark .NET 6.0 .NET 6.0 189.604 ns 2.2500 ns 1.9945 ns 0.58 0.02 0.0315 264 B 1.00
ToPascalCaseBenchmark .NET 7.0 .NET 7.0 170.063 ns 2.5240 ns 2.1076 ns 0.52 0.01 0.0315 264 B 1.00
ToPascalCaseBenchmark .NET Core 3.1 .NET Core 3.1 324.897 ns 6.4022 ns 8.0968 ns 1.00 0.00 0.0315 264 B 1.00
ToTitleCaseBenchmark .NET 5.0 .NET 5.0 281.820 ns 5.5559 ns 4.6395 ns 0.90 0.02 0.0200 168 B 1.00
ToTitleCaseBenchmark .NET 6.0 .NET 6.0 506.287 ns 8.0127 ns 8.9061 ns 1.62 0.05 0.1211 1016 B 6.05
ToTitleCaseBenchmark .NET 7.0 .NET 7.0 485.576 ns 8.4432 ns 8.6705 ns 1.54 0.04 0.1211 1016 B 6.05
ToTitleCaseBenchmark .NET Core 3.1 .NET Core 3.1 314.564 ns 4.8291 ns 4.0325 ns 1.00 0.00 0.0200 168 B 1.00
ToTrainCaseBenchmark .NET 5.0 .NET 5.0 488.572 ns 9.3516 ns 8.7475 ns 0.90 0.02 0.0639 536 B 1.00
ToTrainCaseBenchmark .NET 6.0 .NET 6.0 343.272 ns 4.4961 ns 4.2056 ns 0.63 0.02 0.0639 536 B 1.00
ToTrainCaseBenchmark .NET 7.0 .NET 7.0 302.115 ns 5.8996 ns 6.5574 ns 0.56 0.02 0.0639 536 B 1.00
ToTrainCaseBenchmark .NET Core 3.1 .NET Core 3.1 542.426 ns 10.8240 ns 10.6306 ns 1.00 0.00 0.0639 536 B 1.00
IsAllUpperBenchmark .NET 5.0 .NET 5.0 6.971 ns 0.1332 ns 0.1480 ns 0.74 0.02 - - NA
IsAllUpperBenchmark .NET 6.0 .NET 6.0 5.091 ns 0.1288 ns 0.1533 ns 0.54 0.02 - - NA
IsAllUpperBenchmark .NET 7.0 .NET 7.0 4.166 ns 0.0988 ns 0.1057 ns 0.44 0.01 - - NA
IsAllUpperBenchmark .NET Core 3.1 .NET Core 3.1 9.476 ns 0.0494 ns 0.0385 ns 1.00 0.00 - - NA
ReplaceWhitespaceBenchmark .NET 5.0 .NET 5.0 7,583.997 ns 132.7825 ns 124.2049 ns 0.40 0.01 0.0839 728 B 0.06
ReplaceWhitespaceBenchmark .NET 6.0 .NET 6.0 7,196.590 ns 125.6170 ns 117.5022 ns 0.38 0.01 0.0839 728 B 0.06
ReplaceWhitespaceBenchmark .NET 7.0 .NET 7.0 7,353.717 ns 144.7446 ns 148.6420 ns 0.39 0.02 0.0839 728 B 0.06
ReplaceWhitespaceBenchmark .NET Core 3.1 .NET Core 3.1 18,699.030 ns 362.7740 ns 542.9830 ns 1.00 0.00 1.4343 12168 B 1.00

If you can suggest further improvements please get in touch or better still make the improvements and send us a PR ๐Ÿ˜ƒ

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request ๐Ÿ˜„

License

The MIT License (MIT) See LICENCE file for Licence (MIT Licence)

ยฉ 2021-2023 Captive Reality Ltd. All Rights Reserved. Author: Mark Castle

Product Versions Compatible and additional computed target framework versions.
.NET net5.0 net5.0 was computed.  net5.0-windows net5.0-windows was computed.  net6.0 net6.0 was computed.  net6.0-android net6.0-android was computed.  net6.0-ios net6.0-ios was computed.  net6.0-maccatalyst net6.0-maccatalyst was computed.  net6.0-macos net6.0-macos was computed.  net6.0-tvos net6.0-tvos was computed.  net6.0-windows net6.0-windows was computed.  net7.0 net7.0 was computed.  net7.0-android net7.0-android was computed.  net7.0-ios net7.0-ios was computed.  net7.0-maccatalyst net7.0-maccatalyst was computed.  net7.0-macos net7.0-macos was computed.  net7.0-tvos net7.0-tvos was computed.  net7.0-windows net7.0-windows was computed.  net8.0 net8.0 was computed.  net8.0-android net8.0-android was computed.  net8.0-browser net8.0-browser was computed.  net8.0-ios net8.0-ios was computed.  net8.0-maccatalyst net8.0-maccatalyst was computed.  net8.0-macos net8.0-macos was computed.  net8.0-tvos net8.0-tvos was computed.  net8.0-windows net8.0-windows was computed.  net9.0 net9.0 was computed.  net9.0-android net9.0-android was computed.  net9.0-browser net9.0-browser was computed.  net9.0-ios net9.0-ios was computed.  net9.0-maccatalyst net9.0-maccatalyst was computed.  net9.0-macos net9.0-macos was computed.  net9.0-tvos net9.0-tvos was computed.  net9.0-windows net9.0-windows was computed.  net10.0 net10.0 was computed.  net10.0-android net10.0-android was computed.  net10.0-browser net10.0-browser was computed.  net10.0-ios net10.0-ios was computed.  net10.0-maccatalyst net10.0-maccatalyst was computed.  net10.0-macos net10.0-macos was computed.  net10.0-tvos net10.0-tvos was computed.  net10.0-windows net10.0-windows was computed. 
.NET Core netcoreapp2.0 netcoreapp2.0 was computed.  netcoreapp2.1 netcoreapp2.1 was computed.  netcoreapp2.2 netcoreapp2.2 was computed.  netcoreapp3.0 netcoreapp3.0 was computed.  netcoreapp3.1 netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 netstandard2.0 is compatible.  netstandard2.1 netstandard2.1 is compatible. 
.NET Framework net461 net461 was computed.  net462 net462 was computed.  net463 net463 was computed.  net47 net47 was computed.  net471 net471 was computed.  net472 net472 was computed.  net48 net48 was computed.  net481 net481 was computed. 
MonoAndroid monoandroid monoandroid was computed. 
MonoMac monomac monomac was computed. 
MonoTouch monotouch monotouch was computed. 
Tizen tizen40 tizen40 was computed.  tizen60 tizen60 was computed. 
Xamarin.iOS xamarinios xamarinios was computed. 
Xamarin.Mac xamarinmac xamarinmac was computed. 
Xamarin.TVOS xamarintvos xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.
  • .NETStandard 2.1

    • No dependencies.

NuGet packages (15)

Showing the top 5 NuGet packages that depend on CaseConverter:

Package Downloads
ThunderPropagator.BuildingBlocks

ThunderPropagator (Project ARC): High-performance data propagation; effortless, blazingly fast and cloud-native for maximum impact

Envy

An environment variable loading utility inspired by the Rust crate of the same name.

Spiderly.Shared

Spiderly.Shared package provides shared features that can be used by all other Spiderly packages.

ThunderPropagator.BuildingBlocks.Debug

ThunderPropagator (Project ARC): High-performance data propagation; effortless, blazingly fast and cloud-native for maximum impact

ThunderPropagator.BuildingBlocks.Debug.x86

ThunderPropagator (Project ARC): High-performance data propagation; effortless, blazingly fast and cloud-native for maximum impact

GitHub repositories (3)

Showing the top 3 popular GitHub repositories that depend on CaseConverter:

Repository Stars
LANCommander/LANCommander
minhsangdotcom/clean-architecture
Clean Architecture template for .NET ๐Ÿš€
drasticactions/FishyFlip
Fishyflip - a .NET ATProtocol/Bluesky Library
Version Downloads Last Updated
2.0.1 1,463,070 4/22/2023
2.0.0 340 4/22/2023
1.0.11 1,640 4/21/2023
1.0.10 21,753 11/6/2021
1.0.9 655 11/6/2021
1.0.6 515 11/6/2021
1.0.5 921 11/6/2021