Asal.StringExtentions
1.1.0
See the version list below for details.
dotnet add package Asal.StringExtentions --version 1.1.0
NuGet\Install-Package Asal.StringExtentions -Version 1.1.0
<PackageReference Include="Asal.StringExtentions" Version="1.1.0" />
paket add Asal.StringExtentions --version 1.1.0
#r "nuget: Asal.StringExtentions, 1.1.0"
// Install Asal.StringExtentions as a Cake Addin
#addin nuget:?package=Asal.StringExtentions&version=1.1.0
// Install Asal.StringExtentions as a Cake Tool
#tool nuget:?package=Asal.StringExtentions&version=1.1.0
**How to install Asal.StringExtentions ?
-You can easily install it from Manage Nuget package and write Asal so it will display for you as "Asal.StringExtentions" click download.
**How can I use it ?
-Once you downloaded the package, you can use it on the string itself.. e.g (yourStr."Choose the method that you want to use from the extentions"):-
(1)-> yourStr.ClearSpecialCharacters(optinal param) → This extention take an optional param if you want to replace a space after the char cleared, false by default.
(2)-> yourStr.ClearDigits(optinal param) → This extention take an optional param if you want to replace a space after the digits cleared, false by default.
(3)-> yourStr.Humanize() → Extention to humanize string (separate str by space).
(4)-> yourStr.IsValidEmail() → Extention to check the e-mail if it`s valid or not, return true or false.
(5)-> yourStr.ExtractEmails() → Extention to extract all valid emails in the giving string.
(6)-> yourJsonStrBody.ExtractJsonPropertyValue<T>(string jsonProperty)-> This extention extract a json property value that related to the giving jsonProperty parameter.
Examples:::
****lets say we have a json body like the following : jsonBody = "{"name":"John","age":30,"cars":["Ford", "BMW", "Fiat"]}"
and I want to extract the name of the json property, all you need to do is call the ExtractJsonPropertyValue extention and specify the method return type.
( var result = jsonBody.ExtractJsonPropertyValue<string>("name"); So in this point the result will be as "John". )
Lets say I want to get a property value inside object which is the age ? let
s take another Josn body..
JsonBody = "{"data":[{"baseObject":{"name": "test", "age": 25 }},{"name":"test2"}]}"
answer:
( var result = jsonBody.ExtractJsonPropertyValue<int>("data[0].baseObject.age"); Now, the result will be 25
**what about the name ? var result = jsonBody.ExtractJsonPropertyValue<string>("data[0].baseObject.name"); Now, the result will be "test" )
**How can i extract the object itself ? JsonBody = "{"data":[{"baseObject":{"name": "test", "age": 25 }},{"name":"test2"}]}"
//data[0] represents the first index of the array
answer: ( var result = jsonBody.ExtractJsonPropertyValue<object>("data[0].baseObject"); so the result will be an object that contains the name with it`s value and same for the age. {"name": "test", "age": 25 } )
**How can i get the second object ? JsonBody = "{"data":[{"baseObject":[{"name": "test", "age": 25 }, {"name": "test2", "age": 27 }]},{"name":"test2"}]}"
//baseObject[0] → represents the first object inside baseObject array //baseObject[1] → represents the second object inside baseObject array
answer: ( var result = jsonBody.ExtractJsonPropertyValue<object>("data[0].baseObject[1]"); so the result will be an object that contains the name with it`s value and same for the age. {"name": "test2", "age": 27 }
**Lets say i need now the first object ? var result = jsonBody.ExtractJsonPropertyValue<object>("data[0].baseObject[0]"); so the result will be {"name": "test", "age": 25 }
*****First object name ? var result = jsonBody.ExtractJsonPropertyValue<object>("data[0].baseObject[0].name"); )
(7)-> yourJsonStrBody.TryExtractJsonPropertyValue<T>(string jsonProperty, out T result)-> This extention extract a json property value that related to the giving jsonProperty parameter, a the second parameter represent out result.. so you should specify the T type, no exceptions giving in the extention if it was an error it will return the default of T type in the out result and false as boolean for the method return type.
so after the call happened with success you can use the method value which is bool value Or can take the out result which is the actual data value.
Note: the extraction will be same as ExtractJsonPropertyValue<T>(string jsonProperty) extention but without exceptions.
Example: var input = "{"data":[{"baseObject":{"name": "test", "age": 25 }},{"name":"test2"}]}";
var res = input.TryExtractJsonPropertyValue<int>("data[0].baseObject.age", out var result);
result will be 25
//res value as bool and result have the actual data value depending on the T type
(8)-> yourJsonStrBody.ExtractJsonArrayPropertyValue<T>(string jsonProperty)-> This extention will extract an array values, the return type of it is IEnumerable<T> .
Example: var input = "{"name":"John","age":30,"cars":["Ford", "BMW", "Fiat"]}";
in this example let`s say that i want to get "cars" values which is an array.
answer: ( var res = input.ExtractJsonArrayPropertyValue<string>("cars"); the res value will be List<string> { "Ford", "BMW", "Fiat" } )
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. 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 | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- Microsoft.AspNetCore.Mvc.Core (>= 2.2.5)
-
net6.0
- Microsoft.AspNetCore.Mvc.Core (>= 2.2.5)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Build new extentions for the json values; which is allow to extract json property value and thats include the direct property extraction value or property inside object or even array values and more.