StringExtensionsNetStdIeb 1.6.0
dotnet add package StringExtensionsNetStdIeb --version 1.6.0
NuGet\Install-Package StringExtensionsNetStdIeb -Version 1.6.0
<PackageReference Include="StringExtensionsNetStdIeb" Version="1.6.0" />
paket add StringExtensionsNetStdIeb --version 1.6.0
#r "nuget: StringExtensionsNetStdIeb, 1.6.0"
// Install StringExtensionsNetStdIeb as a Cake Addin #addin nuget:?package=StringExtensionsNetStdIeb&version=1.6.0 // Install StringExtensionsNetStdIeb as a Cake Tool #tool nuget:?package=StringExtensionsNetStdIeb&version=1.6.0
String_Extensions
A big pile of string manipulation methods for C#, to fill in some of the gaps of the default string library.
https://www.nuget.org/packages/StringExtensionsNetStdIeb/
Comparison
CompareWildcard
Match strings to patterns using *
and ?
placeholders. For when Regex is too much.
NaturalComparer
A comparer for use in Linq Sort(...)
that respects numerical ordering.
You can drop this anywhere an IComparer is used on strings. To sort files by name with numbers in the right place:
var list = new DirectoryInfo(@"C:\temp")
.GetFiles()
.OrderBy(f=>f.Name, new NaturalComparer())
.ToList();
.OrderBy(f=>f.Name, new NaturalComparer()).ToList()
Then, given these files (as ordered by default .Net sort)
File 10, File 11, File 8, File 9
Will be sorted correctly, as would be expected:
File 8, File 9, File 10, File 11
NumbersOnlyComparer
Similar to NaturalComparer
, but sorts only on number parts of strings. Strings without numbers are sorted last.
All number values are treated as positive integers, with the -
, .
, ,
characters interpreted as separators.
Given
File
, Users 2020-01-01
, Accounts 2020-02-03
, Accounts 2020-02-03_v2
this will output
Users 2020-01-01
, Accounts 2020-02-03
, Accounts 2020-02-03_v2
, File
EqualsIgnoreNumbers
Compare strings for equality, ignoring the actual values of decimal numbers
NaturalComparer.EqualsIgnoreNumbers("Added ID 5 to DB", "Added ID 201 to DB")
== true
NaturalComparer.EqualsIgnoreNumbers("Added ID 5 to DB", "ID 201 Failed")
== false
Parsing
ToByteArray
Convert hex strings to byte arrays.
Take a string like BADF00BA
into a byte array. String length should be a multiple of two.
Replacement
ReplaceCaseInvariant
Replace string fragments using a case-insensitive search.
Matching is case invariant, replacement is done preserving case.
For example: "OnCe UpOn A tImE".ReplaceCaseInvariant("TiMe", "Moon") == "OnCe UpOn A Moon"
ReplaceAsciiCompatible
Replace latin-like letters and numbers with their ASCII equivalents.
This will replace accented forms with ones that look similar, but it will often destroy or change meaning. Do NOT use this to present output to users. It is intended to use for stored search targets. This is not exhaustive, and does not handle characters that are not latin-like (e.g. CJK)
HÉLLO, Åbjørn!".ReplaceAsciiCompatible() == "HELLO, Abjorn!"
CamelCaseToWords
Convert camelCase
or PascalCase
fused-word strings into space separated words.
MyABCsDoCamelCasePhrase".CamelCaseToWords() == "My ABCs Do Camel Case Phrase"
Switch case simple
Fast case switching on strings that only makes changes that don't change the number of characters in the string.
"123 £%$: AAA aaa lj dž ß".ToUpperSimple() == "123 £%$: AAA AAA LJ DŽ ß"
"123 £%$: AAA aaa LJ DŽ SS".ToLowerSimple() == "123 £%$: aaa aaa lj dž ss"
Switch case of single character
Set casing of characters in the string
"hello, world".UpperCaseIndex(0) == "Hello, world"
"hello, world".UpperCaseIndex(-5) == "hello, World"
Searching
FindCluster
A very simple O(n+m) algorithm for finding clusters of characters in a string.
(i.e. it will find wxyz
in abc zwyx abc
, but not in ab xy ab wz
)
This algorithm will give some false positives where the sum of character values match.
Substrings
A range of substring before/after first/last instances of a character or string.
SubstringBefore
Return the substring up to but not including the first instance of string 's'. If 's' is not found, the entire string is returned.
"once upon a time".SubstringBefore("upon") == "once "
SubstringBeforeLast
Return the substring up to but not including the last instance of string 's'. If 's' is not found, the entire string is returned.
"once upon a time up high".SubstringBeforeLast("up") == "once upon a time "
SubstringAfter
Return the substring after to but not including the first instance of string 's'. If 's' is not found, the entire string is returned.
"it happened once upon a time".SubstringAfter("once") == " upon a time"
SubstringAfterLast
Return the substring after to but not including the last instance of string 's'. If 's' is not found, the entire string is returned.
"once upon a time".SubstringAfterLast("on") == " a time"
IndexAfter / LastIndexAfter
Return the index of the first character after a match.
If match is not found, -1
is returned.
"once upon a time".IndexAfter("on") == 2
"once upon a time".LastIndexAfter("on") == 9
Filtering
NormaliseWhitespace
Replace all runs of whitespace with a single space character
var output = "This\tis\u00a0a story about \r\n a \rperson\n\t\r\n named Not, who was tall."
.NormaliseWhitespace(char.IsLower);
results in This is a story about a person named Not, who was tall.
FilterCharacters
Remove a string omitting characters where the function returns true
var output = "Hello, World! How are you?"
.FilterCharacters(char.IsLower);
results in H, W! H ?
Remove
Return a string with all instances of all given unwanted strings removed, matched case sensitive.
var output = "This is not a short story about a person named Not, who was not short but tall."
.Remove(new[]{"not", "short", "but"})
results in This is a story about a person named Not, who was tall.
RemoveCaseInvariant
Return a string with all instances of all given unwanted strings removed, matched case insensitive.
var output = "This is not a short story about a person named Not, who was not short but tall."
.RemoveCaseInvariant(new[]{"not", "short", "but"})
results in This is a story about a person named , who was tall.
RemoveNumbers
Remove a string omitting all decimal digit characters.
var output = "In 2024 at 12.15pm, we found 7 stone lions in a cave 250 miles from 9th Avenue"
.RemoveNumbers()
results in In at .pm, we found stone lions in a cave miles from th Avenue
RemoveNonAlphaNumeric
Keep only ASCII alphabetic and decimal characters in the string
var output = "In 2024, we found 7 stone lions in a cave 250 miles from 9th Avenue."
.RemoveNonAlphaNumeric()
results in In2024wefound7stonelionsinacave250milesfrom9thAvenue
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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. |
.NET Core | netcoreapp1.0 was computed. netcoreapp1.1 was computed. netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard1.0 is compatible. netstandard1.1 was computed. netstandard1.2 was computed. netstandard1.3 was computed. netstandard1.4 was computed. netstandard1.5 was computed. netstandard1.6 was computed. netstandard2.0 was computed. netstandard2.1 was computed. |
.NET Framework | net45 was computed. net451 was computed. net452 was computed. net46 was computed. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen30 was computed. tizen40 was computed. tizen60 was computed. |
Universal Windows Platform | uap was computed. uap10.0 was computed. |
Windows Phone | wp8 was computed. wp81 was computed. wpa81 was computed. |
Windows Store | netcore was computed. netcore45 was computed. netcore451 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 1.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
unicode tags in ascii conversion