Extensions - Leo-Corporation/LeoCorpLibrary GitHub Wiki
Since the version 2.5.0.2020 of LeoCorpLibrary, a new namespcae has been added: LeoCorpLibrary.Extensions. In this namespace, there is extensions for common types such as string, int, arrays...
If you wanna use those extensions, import the namespace:
C#
using LeoCorpLibrary.Extensions;VB
Import LeoCorpLibrary.ExtensionsThis function is available in version 2.5 and higher.
Compatibility
| Framework | LeoCorpLibrary | LeoCorpLibrary.Core |
|---|---|---|
| .NET 5 | โ | โ |
| .NET Core 3.1 | โ | โ |
| .NET Framework 4.7.2 | โ | โ |
| .NET Framework 4.5 | โ | โ |
The CountWords() method allows you to get the number of words in a string. Returns an int value.
It's in:
LeoCorpLibrary.Extensions.StringExtensions.CountWords()This method has two variation:
Variation 1
This first variation doesn't take any argument.
Variation 2 This method has one argument:
| Value | Argument | Description |
|---|---|---|
| string[] | wordSeparator | The separator of the words. Example: ", ; : ! ? . "
|
Here's an example of usage:
C#
// Variation 1
int numberOfWords = "Hello, this is a test sentence!".CountWords();
// Variation 2
string[] wordSeparator = { " ", ",", ":", "!", "?", ";", "." };
int numberOfWords = "Hello, this is a test sentence!".CountWords(wordSeparator);VB
' Variation 1
Dim numberOfWords As Integer = "Hello, this is a test sentence!".CountWords()
' Variation 2
Dim wordSeparator As String() = {" ", ",", ":", "!", "?", ";", "."}
Dim numberOfWords As Integer = "Hello, this is a test sentence!".CountWords(wordSeparator)This function is available in version 2.6 and higher.
Compatibility
| Framework | LeoCorpLibrary | LeoCorpLibrary.Core |
|---|---|---|
| .NET 5 | โ | โ |
| .NET Core 3.1 | โ | โ |
| .NET Framework 4.7.2 | โ | โ |
| .NET Framework 4.5 | โ | โ |
The Encrypt() method allows you to encrypt a string. It returns a string value.
This method has a few arguments:
| Type | Argument | Description |
|---|---|---|
| string | source | The string to encrypt |
| string | key | The key that will be used to encrypt and decrypt the string |
Here's an example of usage:
C#
string s = "Hello!";
string encrypted = LeoCorpLibrary.Crypt.Encrypt(s, "ABC123");
// Output: jqPW4uxt8hk=VB
Dim s As String = "Hello!"
Dim encrypted As String = LeoCorpLibrary.Crypt.Encrypt(s, "ABC123")
' Output: jqPW4uxt8hk=This function is available in version 2.6 and higher.
Compatibility
| Framework | LeoCorpLibrary | LeoCorpLibrary.Core |
|---|---|---|
| .NET 5 | โ | โ |
| .NET Core 3.1 | โ | โ |
| .NET Framework 4.7.2 | โ | โ |
| .NET Framework 4.5 | โ | โ |
The Decrypt() method allows you to decrypt an encrypted string. It returns a string value.
This method has a few arguments:
| Type | Argument | Description |
|---|---|---|
| string | encrypt | The encrypted string |
| string | key | The key that will be used to encrypt and decrypt the string |
Here's an example of usage:
C#
string encrypted = "jqPW4uxt8hk=";
string decrypted = LeoCorpLibrary.Crypt.Decrypt(encrypted, "ABC123");
// Output: Hello!VB
Dim encrypted As String = "jqPW4uxt8hk="
Dim decrypted As String = LeoCorpLibrary.Crypt.Decrypt(encrypted, "ABC123")
' Output: Hello!This function is available in version 3.2 and higher.
Compatibility
| Framework | LeoCorpLibrary | LeoCorpLibrary.Core |
|---|---|---|
| .NET 5 | โ | โ |
| .NET Core 3.1 | โ | โ |
| .NET Framework 4.7.2 | โ | โ |
| .NET Framework 4.5 | โ | โ |
The UpperFirstLetter() method allows you to upper the first letter of a string. It returns a string value.
Here's an example of usage:
C#
string helloMsg = "hello, this is a test"; // String
Console.WriteLine(helloMsg.UpperFirstLetter());
// Output:
// Hello, this is a testVB
Dim helloMsg As String = "hello, this is a test" ' String
Console.WriteLine(helloMsg.UpperFirstLetter())
' Output:
' Hello, this is a testThis function is available in version 3.4 and higher.
Compatibility
| Framework | LeoCorpLibrary | LeoCorpLibrary.Core |
|---|---|---|
| .NET 5 | โ | โ |
| .NET Core 3.1 | โ | โ |
| .NET Framework 4.7.2 | โ | โ |
| .NET Framework 4.5 | โ | โ |
This method allows you to upper letters from a starting index, and an end index. It returns a string value.
This method has a few arguments:
| Type | Argument | Description |
|---|---|---|
| int | startIndex | The position where letters should start be in upper case |
| int | length | The position where letters should stop be in upper case |
Here's an example of usage:
C#
string s = "I want leocorplibrary in upper case".UpperLettersAt(7, 20);
// Value of s:
// "I want LEOCORPLIBRARY in upper case"VB
Dim s As String = "I want leocorplibrary in upper case".UpperLettersAt(7, 20)
' Value of s:
' "I want LEOCORPLIBRARY in upper case"This function is available in version 3.4 and higher.
Compatibility
| Framework | LeoCorpLibrary | LeoCorpLibrary.Core |
|---|---|---|
| .NET 5 | โ | โ |
| .NET Core 3.1 | โ | โ |
| .NET Framework 4.7.2 | โ | โ |
| .NET Framework 4.5 | โ | โ |
This method allows you to compare if two string values are ending with the same punctuation. It returns a bool value.
Variation 1
IsEndingWithSamePunctuation(string stringToCheck) {...}This first variation has one argument:
| Type | Argument | Description |
|---|---|---|
| string | stringToCheck | The string to compare |
Variation 2
IsEndingWithSamePunctuation(string stringToCheck, string punctuationToCheck) {...}This second variation has two arguments:
| Type | Argument | Description |
|---|---|---|
| string | stringToCheck | The string to compare |
| string | punctuationToCheck | The punctuation sign to check for |
Here's an example of usage:
C#
// Variation 1
string a = "This is a test sentence.";
string b = "This is an another test sentence.";
a.IsEndingWithSamePunctuation(b); // Returns true
// Variation 2
a.IsEndingWithSamePunctuation(b, "."); // Returns trueVB
' Variation 1
Dim a As String = "This is a test sentence."
Dim b As String = "This is an another test sentence."
a.IsEndingWithSamePunctuation(b) ' Returns true
' Variation 2
a.IsEndingWithSamePunctuation(b, ".") ' Returns trueThis function is available in version 3.6 and higher.
Compatibility
| Framework | LeoCorpLibrary | LeoCorpLibrary.Core |
|---|---|---|
| .NET 5 | โ | โ |
| .NET Core 3.1 | โ | โ |
| .NET Framework 4.7.2 | โ | โ |
| .NET Framework 4.5 | โ | โ |
The SplitLines() method allows you to split a string with multiple lines, and put each line of this string into an array of string. It returns a string[] value.
This method has no argument.
Here's an example of usage:
C#
string text = "Hello,\nWorld!";
string[] lines = text.SplitLines();
// lines[0] = Hello,
// lines[1] = World!VB
Dim text As String = "Hello," & vbLf & "World!"
Dim lines As String() = text.SplitLines()
' lines[0] = Hello,
' lines[1] = World!This function is available in version 3.8 and higher.
Compatibility
| Framework | LeoCorpLibrary | LeoCorpLibrary.Core |
|---|---|---|
| .NET 5 | โ | โ |
| .NET Core 3.1 | โ | โ |
| .NET Framework 4.7.2 | โ | โ |
| .NET Framework 4.5 | โ | โ |
The HasRepeatedCharacters() method allows you to know if a string has repeated characters. It returns a bool value.
It's in:
LeoCorpLibrary.Extensions.StringExtensions.HasRepeatedCharacters()This method doesn't take any argument.
Here's an example of usage:
C#
bool r = "aabb".HasRepeatedCharacters();
// r = trueVB
Dim r As Boolean = "aabb".HasRepeatedCharacters()
' r = trueThis function is available in version 2.5 and higher.
Compatibility
| Framework | LeoCorpLibrary | LeoCorpLibrary.Core |
|---|---|---|
| .NET 5 | โ | โ |
| .NET Core 3.1 | โ | โ |
| .NET Framework 4.7.2 | โ | โ |
| .NET Framework 4.5 | โ | โ |
The IsEven() method allows you to know if a specic int is even. Returns a bool value.
It's in:
LeoCorpLibrary.Extensions.IntExtensions.IsEven()This method doesn't take any argument.
Here's an example of usage:
C#
bool even = 12.IsEven(); // Returns true
bool odd = 11.IsEven(); // Returns falseVB
Dim even As Boolean = 12.IsEven() ' Returns true
Dim odd As Boolean = 11.IsEven() ' Returns falseThis function is available in version 2.5 and higher.
Compatibility
| Framework | LeoCorpLibrary | LeoCorpLibrary.Core |
|---|---|---|
| .NET 5 | โ | โ |
| .NET Core 3.1 | โ | โ |
| .NET Framework 4.7.2 | โ | โ |
| .NET Framework 4.5 | โ | โ |
The ToDouble() method allows you to convert an รฌnt value to a double value. Returns a double value.
It's in:
LeoCorpLibrary.Extensions.IntExtensions.IsEven()This method doesn't take any argument.
Here's an example of usage:
C#
int a = 15;
int b = 2;
double result = a.ToDouble() / b.ToDouble();VB
Dim a As Integer = 15
Dim b As Integer = 2
Dim result As Double = a.ToDouble() / b.ToDouble()This function is available in version 3.6 and higher.
Compatibility
| Framework | LeoCorpLibrary | LeoCorpLibrary.Core |
|---|---|---|
| .NET 5 | โ | โ |
| .NET Core 3.1 | โ | โ |
| .NET Framework 4.7.2 | โ | โ |
| .NET Framework 4.5 | โ | โ |
The ConvertSizeUnitToByte() method allows you to convert a size unit such as kilobyte, gigabyte to byte. It returns a double value.
It's in:
LeoCorpLibrary.Extensions.IntExtensions.ConvertSizeUnitToByte()It has one argument:
| Value | Argument | Description |
|---|---|---|
| UnitType | unitType | The source unit (kb, mb...) |
Here's an example of usage:
C#
int kiloByte = 5000;
double byteVar = kiloByte.ConvertSizeUnitToByte(UnitType.Kilobyte);
// Expected value for byteVar: 5000000VB
Dim kiloByte As Integer = 5000
Dim byteVar As Double = kiloByte.ConvertSizeUnitToByte(UnitType.Kilobyte)
' Expected value for byteVar: 5000000This function is available in version 3.6 and higher.
Compatibility
| Framework | LeoCorpLibrary | LeoCorpLibrary.Core |
|---|---|---|
| .NET 5 | โ | โ |
| .NET Core 3.1 | โ | โ |
| .NET Framework 4.7.2 | โ | โ |
| .NET Framework 4.5 | โ | โ |
The ConvertSizeUnitToKilobyte() method allows you to convert a size unit such as kilobyte, gigabyte to kilobyte. It returns a double value.
It's in:
LeoCorpLibrary.Extensions.IntExtensions.ConvertSizeUnitToKilobyte()It has one argument:
| Value | Argument | Description |
|---|---|---|
| UnitType | unitType | The source unit (kb, mb...) |
Here's an example of usage:
C#
int megaByte = 50;
double kiloByte = megaByte.ConvertSizeUnitToKilobyte(UnitType.Megabyte);
// Expected value for kiloByte: 50000VB
Dim megaByte As Integer = 50
Dim kiloByte As Double = megaByte.ConvertSizeUnitToKilobyte(UnitType.Megabyte)
' Expected value for kiloByte: 50000This function is available in version 3.6 and higher.
Compatibility
| Framework | LeoCorpLibrary | LeoCorpLibrary.Core |
|---|---|---|
| .NET 5 | โ | โ |
| .NET Core 3.1 | โ | โ |
| .NET Framework 4.7.2 | โ | โ |
| .NET Framework 4.5 | โ | โ |
The ConvertSizeUnitToMegabyte() method allows you to convert a size unit such as megabyte, gigabyte to megabyte. It returns a double value.
It's in:
LeoCorpLibrary.Extensions.IntExtensions.ConvertSizeUnitToMegabyte()It has one argument:
| Value | Argument | Description |
|---|---|---|
| UnitType | unitType | The source unit (kb, mb...) |
Here's an example of usage:
C#
int gigaByte = 50;
double megaByte = gigaByte.ConvertSizeUnitToMegabyte(UnitType.Gigabyte);
// Expected value for megaByte: 50000VB
Dim gigaByte As Integer = 50
Dim megaByte As Double = gigaByte.ConvertSizeUnitToMegabyte(UnitType.Gigabyte)
' Expected value for megaByte: 50000This function is available in version 3.6 and higher.
Compatibility
| Framework | LeoCorpLibrary | LeoCorpLibrary.Core |
|---|---|---|
| .NET 5 | โ | โ |
| .NET Core 3.1 | โ | โ |
| .NET Framework 4.7.2 | โ | โ |
| .NET Framework 4.5 | โ | โ |
The ConvertSizeUnitToGigabyte() method allows you to convert a size unit such as megabyte, petabyte to gigabyte. It returns a double value.
It's in:
LeoCorpLibrary.Extensions.IntExtensions.ConvertSizeUnitToGigabyte()It has one argument:
| Value | Argument | Description |
|---|---|---|
| UnitType | unitType | The source unit (kb, mb...) |
Here's an example of usage:
C#
int megaByte = 4400;
double gigaByte = megaByte.ConvertSizeUnitToGigabyte(UnitType.Megabyte);
// Expected value for gigaByte: 4VB
Dim megaByte As Integer = 4400
Dim gigaByte As Double = megaByte.ConvertSizeUnitToGigabyte(UnitType.Megabyte)
' Expected value for gigaByte: 4This function is available in version 3.6 and higher.
Compatibility
| Framework | LeoCorpLibrary | LeoCorpLibrary.Core |
|---|---|---|
| .NET 5 | โ | โ |
| .NET Core 3.1 | โ | โ |
| .NET Framework 4.7.2 | โ | โ |
| .NET Framework 4.5 | โ | โ |
The ConvertSizeUnitToTerabyte() method allows you to convert a size unit such as megabyte, petabyte to terabyte. It returns a double value.
It's in:
LeoCorpLibrary.Extensions.IntExtensions.ConvertSizeUnitToTerabyte()It has one argument:
| Value | Argument | Description |
|---|---|---|
| UnitType | unitType | The source unit (kb, mb...) |
Here's an example of usage:
C#
int gigaByte = 2000;
double teraByte = gigaByte.ConvertSizeUnitToTerabyte(UnitType.Gigabyte);
// Expected value for teraByte: 2VB
Dim gigaByte As Integer = 2000
Dim teraByte As Double = gigaByte.ConvertSizeUnitToTerabyte(UnitType.Gigabyte)
' Expected value for teraByte: 2This function is available in version 3.6 and higher.
Compatibility
| Framework | LeoCorpLibrary | LeoCorpLibrary.Core |
|---|---|---|
| .NET 5 | โ | โ |
| .NET Core 3.1 | โ | โ |
| .NET Framework 4.7.2 | โ | โ |
| .NET Framework 4.5 | โ | โ |
The ConvertSizeUnitToPetabyte() method allows you to convert a size unit such as megabyte, terabyte to petabyte. It returns a double value.
It's in:
LeoCorpLibrary.Extensions.IntExtensions.ConvertSizeUnitToPetabyte()It has one argument:
| Value | Argument | Description |
|---|---|---|
| UnitType | unitType | The source unit (kb, mb...) |
Here's an example of usage:
C#
int teraByte = 6000;
double petaByte = teraByte.ConvertSizeUnitToPetabyte(UnitType.Terabyte);
// Expected value for petaByte: 6VB
Dim teraByte As Integer = 6000
Dim petaByte As Double = teraByte.ConvertSizeUnitToPetabyte(UnitType.Terabyte)
' Expected value for petaByte: 6This function is available in version 2.5 and higher.
Compatibility
| Framework | LeoCorpLibrary | LeoCorpLibrary.Core |
|---|---|---|
| .NET 5 | โ | โ |
| .NET Core 3.1 | โ | โ |
| .NET Framework 4.7.2 | โ | โ |
| .NET Framework 4.5 | โ | โ |
The Append() method allows you to append an item or multiple items to an array. Returns a T[] value.
It's in:
LeoCorpLibrary.Extensions.ArrayExtensions.Append()This method has two variations:
Variation 1
| Value | Argument | Description |
|---|---|---|
| T | item | The item which is going to be append in the array |
Variation 2
| Value | Argument | Description |
|---|---|---|
| params T[] | items | The items which are going to be append in the array |
Here's an example of usage:
C#
// Variation 1
int[] numbers = { 1, 2, 3, 4 };
int[] appendNumbers = numbers.Append(5);
// appendNumbers: { 1, 2, 3, 4, 5 }
// Variation 2
int[] numbers = { 1, 2, 3, 4 };
int[] appendNumbers = numbers.Append(5, 6);
// appendNumbers: { 1, 2, 3, 4, 5, 6 }VB
' Variation
Dim numbers As Integer() = {1, 2, 3, 4}
Dim appendNumbers As Integer() = numbers.Append(5)
' appendNumbers: { 1, 2, 3, 4, 5 }
' Variation 2
Dim numbers As Integer() = {1, 2, 3, 4}
Dim appendNumbers As Integer() = numbers.Append(5, 6)
' appendNumbers: { 1, 2, 3, 4, 5, 6 }This function is available in version 2.5 and higher.
Compatibility
| Framework | LeoCorpLibrary | LeoCorpLibrary.Core |
|---|---|---|
| .NET 5 | โ | โ |
| .NET Core 3.1 | โ | โ |
| .NET Framework 4.7.2 | โ | โ |
| .NET Framework 4.5 | โ | โ |
The RemoveItem() method allows you to remove a specific item from an array. It returns a T[] value.
It's in:
LeoCorpLibrary.Extensions.ArrayExtensions.RemoveItem()This method has two variations:
Variation 1
| Value | Argument | Description |
|---|---|---|
| T | item | The item to remove |
Variation 2
| Value | Argument | Description |
|---|---|---|
| params T[] | items | The items to remove |
Here's an example of usage:
C#
// Variation 1
int[] numbers = { 1, 2, 3, 4, 5 };
int[] remove = numbers.RemoveItem(5);
// remove: { 1, 2, 3, 4 }
// Variation 2
int[] numbers = { 1, 2, 3, 4, 5 };
int[] remove = numbers.RemoveItem(5, 3);
// remove: { 1, 2, 4 }VB
' Variation 1
Dim numbers As Integer() = {1, 2, 3, 4, 5}
Dim remove As Integer() = numbers.RemoveItem(5)
' remove: { 1, 2, 3, 4 }
' Variation 2
Dim numbers As Integer() = {1, 2, 3, 4, 5}
Dim remove As Integer() = numbers.RemoveItem(5, 3)
' remove: { 1, 2, 4 }This function is available in version 3.6 and higher.
Compatibility
| Framework | LeoCorpLibrary | LeoCorpLibrary.Core |
|---|---|---|
| .NET 5 | โ | โ |
| .NET Core 3.1 | โ | โ |
| .NET Framework 4.7.2 | โ | โ |
| .NET Framework 4.5 | โ | โ |
The UnSplit() method allows you to unsplit an array of string using a separator. It returns a string value.
It's in:
LeoCorpLibrary.Extensions.ArrayExtensions.UnSplit()It has one argument:
| Value | Argument | Description |
|---|---|---|
| string | separator | The separator to insert between items. |
Here's an example of usage:
C#
string[] array = { "a", "b", "c", "d" };
string unSplit = array.UnSplit(";");
// Output:
// a;b;c;dVB
Dim array As String() = {"a", "b", "c", "d"}
Dim unSplit As String = array.UnSplit(";")
' Output:
' a;b;c;d