VTNET.Extensions 7.1.9

dotnet add package VTNET.Extensions --version 7.1.9                
NuGet\Install-Package VTNET.Extensions -Version 7.1.9                
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="VTNET.Extensions" Version="7.1.9" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add VTNET.Extensions --version 7.1.9                
#r "nuget: VTNET.Extensions, 7.1.9"                
#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.
// Install VTNET.Extensions as a Cake Addin
#addin nuget:?package=VTNET.Extensions&version=7.1.9

// Install VTNET.Extensions as a Cake Tool
#tool nuget:?package=VTNET.Extensions&version=7.1.9                

Library Name

Library Name is a collection of utility methods for manipulating various data types.

Features

  • Check if a string is a number: "1000".IsNumber()
  • Check if a number is even: 69.IsEven()
  • Check if a number is odd: 96.IsOdd()
  • Convert a number to words: "1000".ToWords()
  • Format a number as currency: 1000.ToCurrency()
  • Remove spaces from a string: "a b c".RemoveDuplicateSpaces()
  • Capitalize the first letter of each word in a string: "vo thanh thuan".ToCapitalize()
  • Convert a string to title case: "vo thanh thuan".ToTitle()
  • Convert a string to title case: StringEx.Lorem
  • Convert DataTable to List: var list = dataTable.ToList<model>()
  • Support string methods: IsNullOrEmpty(), IsNullOrWhiteSpace()
  • Perform calculations on a string expression: "1+1".Calculate()
    • sin: "sin(30)".Calculate()
    • tan: "tan(30)".Calculate()
    • cos: "cos(30)".Calculate()
    • log: "log(30)".Calculate()
    • factorial: "4!".Caculate()
    • percent: "44%".Caculate()

Installation

You can install the library via NuGet Package Manager. Simply search for Library Name and install the latest version.

Usage

Here is an example of how to use the library:

using VTNET.Extensions;
"Hello".Log(); //Hello

String

string number2 = "1000";
string words = number2.ToWords(); // "one thousand"

int amount = 1000;
string formattedAmount = amount.Separator(); // "1,000.00"

string text = "a   b       c";
string trimmedText = text.RemoveDuplicateSpaces(); // "a b c"

string name = "vo thanh thuan";
string capitalized = name.ToCapitalize(); // "Vo thanh thuan"

string title = "VO THANH THUAN";
string titleCase1 = title.ToTitle(ignoreUpperCase:true); // "VO THANH THUAN"
string titleCase2 = title.ToTitle(ignoreUpperCase:false); // "Vo Thanh Thuan"

string reverseString = "Thuaanj".ReverseString(); // "jnaauhT"

",".Join(listValue); //like string.Join(",", listValue);

StringEx.IsNumericString("-3.14").Log(); //true
StringEx.IsNumericString("1,000,000.34", ',').Log(); //true

string lorem = StringEx.Lorem; // "lorem ipsum dolor sit"
string lorem = StringEx.LoremShort; // "lorem ipsum dolor sit"
string lorem = StringEx.LoremLong; // "lorem ipsum dolor sit..."
string lorem = StringEx.LoremIpsum(minWords: 4, maxWords: 64, minSentences: 1, maxSentences: 4, numParagraphs: 4); // "lorem ipsum dolor sit..."

//Convert a number to words:
1000.ToWords(); // "one thousand"

//Set Language
Console.OutputEncoding = Encoding.UTF8;

StringEx.SetLanguageToWords(LangWords.VN);

1000.ToWords(); // "một nghìn"

"abc".Contains(x => x.TextOnly).Log(); //true
"123abc".Contains(x => x.TextOnly).Log(); //false
"abc".Contains(x => x.Number).Log(); //false
"123abc".Contains(x => x.NumberOnly).Log(); //false
"123abc".Contains(x => x.Number).Log(); //true

//Simple algorithm for calculating string similarity
var levenshtein = StringAnalysis.LevenshteinDistance("võ thành thuận", "võ thành thuặn");// 1

Number

int num = 69;
bool isEven = num.IsEven(); // false

int num2 = 96;
bool isOdd = num2.IsOdd(); // true

"69".ParseInt();
"6.9".ParseFloat();
"3.14".ParseDouble();

Calculate

"sin(30)".Calculate(); //sin(30)> -0.9880316240928618
"sin(30deg)".Calculate(); //sin(30deg)> 0.49999999999999994

"tan(30)".Calculate(); //tan(30)> -6.405331196646276
"tan(30deg)".Calculate(); //tan(30deg)> 0.5773502691896257

"cos(30)".Calculate(); //cos(30)> 0.15425144988758405
"cos(30deg)".Calculate(); //cos(30deg)>0.8660254037844387

"log(30)".Calculate(); //log(30)> 1.4771212547196624

"4!".Calculate(); //4!> 44
"44%".Calculate(); //44%> 0.44

///Custom function
//One parameter
CalculateEx.AddSimpleFunction("addone", num =>
{
    return ++num;
});
//Many parameter
CalculateEx.AddFunction("sum", agrs =>
{
    return agrs.Sum();
});
//Operator
CalculateEx.AddOperator('?', (a, b) =>
{
    return Random.Shared.Next((int)a, (int)b);
}, 3);

CalculateEx.AddOperator('#', Math.Max, 3);


"addone(1)> ".Log("addone(1)".Calculate()); //2
"1?100> ".Log("1?100".Calculate());
"sum(1;2;3;4;5;6)> ".Log("sum(1;2;3;4;5;6)".Calculate()); //21
"1#2#3#6#5#4> ".Log("1#2#3#6#5#4".Calculate()); //6

//Degree and Radian
CalculateEx.AddSimpleFunction("circle", (num, isDeg) =>
{
    return isDeg ? num*360 : num;
});
CalculateEx.AddFunction("circleSum", (agrs, isDeg) =>
{
    return isDeg ? agrs.Sum() * 360 : agrs.Sum();
});
"circle(1/8deg)".Calculate(); //45
"circleSum(1/8;1/8deg)".Calculate(); //90

//Change CultureInfo
"3.14+1".Calculate().Log(); //4.14
CalculateEx.Culture = new CultureInfo("vi-VN");
"3.14+1".Calculate().Log(); //315
"3,14+1".Calculate().Log(); //4.14

DataTable To List

var list = dataTable.ToList<model>();

//Match column name
var list2 = dataTable.ToList<model>(matchCase: true);

//Convert with cache
var list2 = dataTable.ToListCache<model>(matchCase: true);

//Convert List<Dictionary<string, object?>> to DataTable
var dic = new List<Dictionary<string, object?>>
        {
            new() { { "ID", 1 }, { "Name", "John" }, { "Age", 30 } },
            new() { { "ID", 2 }, { "Name", "Alice" }, { "Age", 25 } },
            new() { { "ID", 3 }, { "Name", "Bob" }, { "Age", null } }
        };
var table = dic.ToDataTable();
var valueMap = table.ToList<TestTable>();

//Specify the column name other fields
class TestTable
{
    [MapColumnName("Id")]
    public string Idx { get; set; } = "";
    [IgnoreMapColumnName]
    public string Name { get; set; } = "";
    public string Age { get; set; } = "";
}

String Analysis

The StringAnalysis library provides powerful methods for identifying and manipulating patterns within strings, offering enhanced string processing capabilities. Below are examples of some key functions:

1. Function Extraction

The Functions method extracts function information, including function name, parameters, and code block from the input string.

var function = StringAnalysis.Functions("testfunc(this is param){this is code}");//{FuncName: testfunc, Param: this is param, Code: this is code}
2. Function Call Extraction

The FunctionsCall method retrieves function calls and their corresponding parameters from the input string.

var functionCall = StringAnalysis.FunctionsCall("testfunc1(param one)testfunc2(param two)");//[(testfunc1,param one), (testfunc2,param two)]
3. Function Parameters Extraction

The FunctionParams method extracts parameters enclosed within parentheses from the input string.

var functionParams = StringAnalysis.FunctionParams("(param one)(param two)(param three)");//[param one, param two,param three]
4. Language-based Replacement

The ReplaceByLanguage method performs language-based replacements in the input string. In the provided example, if the current display language is set to Vietnamese (vi-VN), the method will replace language codes with their corresponding values, returning "Tiếng Việt" as the result.

var replaceByLang = StringAnalysis.ReplaceByLanguage("vi(Tiếng Việt)en(Tiếng anh)");// Example: If the current display language is vi-VN, the result will be "Tiếng Việt"
5. Custom Function-based Replacement

The ReplaceByFunc method enables custom replacements based on a specified function. In this example, it replaces occurrences of calc with the result of the provided calculation.

var replaceByFunc = StringAnalysis.ReplaceByFunc("the result of the calculation 3*6 is calc(3*6)","calc", data =>
{
    return data.Calculate().ToString();
}); //the result of the calculation 3*6 is 18

TypeEx

TypeEx adds a few small extensions to help make data processing simpler.

    var defaultValue = typeof(T).GetDefaultValue(); //T is generic type

DataRow (DataTableEx)

The extensions (Get, Set) for DataRow will help you simplify retrieving data and assigning data to DataRow. You no longer have to handle null and DBNull cases yourself, making the code more compact.

    var row = DataTable.Rows[0];
    var val1 = row.GetValue<int>("id");
    var val2 = row.GetStringValue("name");
    row.SetValue("name", "vothuan");

Feel free to explore the full range of functionalities offered by the StringAnalysis library to enhance your string processing tasks.

v2 for standard 2.1 v7 for .NET7

V7

Add the Params class. Similar to a Dictionary, but more convenient.

var p = new Params();
var p1 = new Params(("key", "value"), ("key1", "value1"))
var val1 = p1.Get<string>("key"); //value

var p2 = new Params(1,2,3,4,5,6,7,8,9)
var val2 = p2[3]; //4
Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net7.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on VTNET.Extensions:

Package Downloads
VTNET.Vitado

An ADO.NET wrapper library

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
7.1.9 136 9/17/2024
7.1.8 128 8/14/2024
7.1.7 150 7/16/2024
7.1.6 103 7/16/2024 7.1.6 is deprecated because it has critical bugs.
7.1.5 128 7/16/2024 7.1.5 is deprecated because it has critical bugs.
7.1.4 106 7/15/2024 7.1.4 is deprecated because it has critical bugs.
7.1.3 114 7/15/2024 7.1.3 is deprecated because it is no longer maintained.
7.1.2 190 5/7/2024 7.1.2 is deprecated because it is no longer maintained.
7.1.1 151 5/7/2024 7.1.1 is deprecated because it is no longer maintained.
7.1.0 118 5/2/2024 7.1.0 is deprecated because it is no longer maintained.
7.0.3 184 2/28/2024 7.0.3 is deprecated because it is no longer maintained.
7.0.2 149 2/27/2024 7.0.2 is deprecated because it is no longer maintained.
7.0.1 200 2/21/2024 7.0.1 is deprecated because it is no longer maintained.
7.0.0 144 2/21/2024 7.0.0 is deprecated because it is no longer maintained.
2.1.4 153 1/18/2024
2.1.3 184 1/15/2024 2.1.3 is deprecated because it is no longer maintained.
2.1.2 198 12/22/2023 2.1.2 is deprecated because it is no longer maintained.
2.1.1 198 12/3/2023 2.1.1 is deprecated because it is no longer maintained.
2.1.0 165 12/3/2023 2.1.0 is deprecated because it is no longer maintained.
2.0.3 161 12/2/2023 2.0.3 is deprecated because it is no longer maintained.
2.0.2 187 11/21/2023 2.0.2 is deprecated because it is no longer maintained.
2.0.1 188 11/3/2023 2.0.1 is deprecated because it is no longer maintained.
2.0.0 265 10/12/2023 2.0.0 is deprecated because it is no longer maintained.
1.4.11 189 9/27/2023 1.4.11 is deprecated because it is no longer maintained.
1.4.10 280 9/8/2023 1.4.10 is deprecated because it is no longer maintained.
1.4.9 162 9/6/2023 1.4.9 is deprecated because it is no longer maintained.
1.4.8 160 9/6/2023 1.4.8 is deprecated because it has critical bugs.
1.4.7 176 9/5/2023 1.4.7 is deprecated because it is no longer maintained.
1.4.6 197 8/31/2023 1.4.6 is deprecated because it is no longer maintained.
1.4.5 215 8/22/2023 1.4.5 is deprecated because it is no longer maintained.
1.4.4 203 8/22/2023 1.4.4 is deprecated because it is no longer maintained.
1.4.3 209 8/11/2023 1.4.3 is deprecated because it is no longer maintained.
1.4.2 212 8/10/2023 1.4.2 is deprecated because it has critical bugs.
1.4.1 193 8/10/2023 1.4.1 is deprecated because it has critical bugs.
1.4.0 296 8/3/2023 1.4.0 is deprecated because it has critical bugs.
1.3.0-beta 195 6/9/2023 1.3.0-beta is deprecated because it has critical bugs.
1.2.1-beta 174 6/7/2023 1.2.1-beta is deprecated because it has critical bugs.
1.2.0-beta 165 6/6/2023 1.2.0-beta is deprecated.
1.1.2-beta 163 5/31/2023 1.1.2-beta is deprecated.
1.1.1-beta 164 5/31/2023 1.1.1-beta is deprecated.
1.1.0-beta 175 5/30/2023 1.1.0-beta is deprecated.
1.0.1-beta 173 5/25/2023 1.0.1-beta is deprecated.
1.0.0-beta 160 5/25/2023 1.0.0-beta is deprecated.