VTNET.Extensions
7.0.0
See the version list below for details.
dotnet add package VTNET.Extensions --version 7.0.0
NuGet\Install-Package VTNET.Extensions -Version 7.0.0
<PackageReference Include="VTNET.Extensions" Version="7.0.0" />
paket add VTNET.Extensions --version 7.0.0
#r "nuget: VTNET.Extensions, 7.0.0"
// Install VTNET.Extensions as a Cake Addin #addin nuget:?package=VTNET.Extensions&version=7.0.0 // Install VTNET.Extensions as a Cake Tool #tool nuget:?package=VTNET.Extensions&version=7.0.0
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()
- sin:
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
Feel free to explore the full range of functionalities offered by the StringAnalysis library to enhance your string processing tasks.
Product | Versions 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. |
-
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 | 126 | 9/17/2024 | |
7.1.8 | 122 | 8/14/2024 | |
7.1.7 | 144 | 7/16/2024 | |
7.1.6 | 99 | 7/16/2024 | |
7.1.5 | 124 | 7/16/2024 | |
7.1.4 | 99 | 7/15/2024 | |
7.1.3 | 106 | 7/15/2024 | |
7.1.2 | 186 | 5/7/2024 | |
7.1.1 | 144 | 5/7/2024 | |
7.1.0 | 114 | 5/2/2024 | |
7.0.3 | 180 | 2/28/2024 | |
7.0.2 | 145 | 2/27/2024 | |
7.0.1 | 196 | 2/21/2024 | |
7.0.0 | 140 | 2/21/2024 | |
2.1.4 | 151 | 1/18/2024 | |
2.1.3 | 180 | 1/15/2024 | |
2.1.2 | 194 | 12/22/2023 | |
2.1.1 | 194 | 12/3/2023 | |
2.1.0 | 161 | 12/3/2023 | |
2.0.3 | 157 | 12/2/2023 | |
2.0.2 | 183 | 11/21/2023 | |
2.0.1 | 184 | 11/3/2023 | |
2.0.0 | 260 | 10/12/2023 | |
1.4.11 | 185 | 9/27/2023 | |
1.4.10 | 276 | 9/8/2023 | |
1.4.9 | 158 | 9/6/2023 | |
1.4.8 | 156 | 9/6/2023 | |
1.4.7 | 172 | 9/5/2023 | |
1.4.6 | 193 | 8/31/2023 | |
1.4.5 | 210 | 8/22/2023 | |
1.4.4 | 199 | 8/22/2023 | |
1.4.3 | 205 | 8/11/2023 | |
1.4.2 | 210 | 8/10/2023 | |
1.4.1 | 190 | 8/10/2023 | |
1.4.0 | 294 | 8/3/2023 | |
1.3.0-beta | 194 | 6/9/2023 | |
1.2.1-beta | 174 | 6/7/2023 | |
1.2.0-beta | 165 | 6/6/2023 | |
1.1.2-beta | 163 | 5/31/2023 | |
1.1.1-beta | 164 | 5/31/2023 | |
1.1.0-beta | 175 | 5/30/2023 | |
1.0.1-beta | 172 | 5/25/2023 | |
1.0.0-beta | 160 | 5/25/2023 |