TsadriuUtilities 1.13.1
dotnet add package TsadriuUtilities --version 1.13.1
NuGet\Install-Package TsadriuUtilities -Version 1.13.1
<PackageReference Include="TsadriuUtilities" Version="1.13.1" />
paket add TsadriuUtilities --version 1.13.1
#r "nuget: TsadriuUtilities, 1.13.1"
// Install TsadriuUtilities as a Cake Addin #addin nuget:?package=TsadriuUtilities&version=1.13.1 // Install TsadriuUtilities as a Cake Tool #tool nuget:?package=TsadriuUtilities&version=1.13.1
TsadriuUtilities
A package with utilities that are useful for web scraping, to make it easier and save a little bit of time.
TsadriuUtilities is a library that helps on dealing with
- Arrays, Chars, Directories, Files, Lists, Numbers, Strings, Generic types and more. I hope this package will make your coding easier and save you a bit of time.
> Features <
ArrayHelper:
- ToString<T>(T[], string separator):
- Converts an
Array
into a single line of string. If theseparator
is not passed, it will separate by a space. Examples: ArrayToString(new int[] { 1, 3, 5 }) → "1 3 5", ArrayToString(new string[] { "5", "2" }, "|") → "5|2".
- Converts an
- GenerateRandom<T>(T[] array, int min, int max):
- Fills up the
array
with random numbers betweenmin
(default: 0, inclusive) andmax
(default: 100, inclusive).
- Fills up the
- GetValueLike(string[] stringArray, string value, StringComparison stringComparison)
- Iterates through the
stringArray
, returning the first item found that containsvalue
.
- Iterates through the
- GetValueContaining(string[] stringArray, StringComparison stringComparison, string[] values)
- Iterates through the
stringArray
, returning the first item found that contains all thevalues
.
- Iterates through the
- AddToElements(string[] stringArray, string startItemTag, string endItemTag)
- Iterates through the
stringArray
, addingstartItemTag
before the item andendItemTag
after the item. Example:startItemTag
is 'www.' and the items inside thestringArray
are 'google.com'. This method will return the elements as 'www.google.com'.
- Iterates through the
- RemoveFromElements(string[] stringArray, params string[] valuesToRemove)
- Returns an array where all occasions of
valuesToRemove
have been removed from the elements of thestringArray
.
- Returns an array where all occasions of
- ReplaceFromElements(string[] stringArray, string oldValue, string newValue)
- Returns an array where all occasions of
oldValue
have been replaced bynewValue
from the elements of thestringArray
.
- Returns an array where all occasions of
- GetBetween(string[] stringArray, string start, string end, bool startEndIncluded):
- Iterates through the
stringArray
, returning the first instance where bothstart
andend
are found. If none of the indexes matchstart
andend
, astring.Empty
is returned. UsestartEndIncluded
if you want to includestart
andend
in the returning string.
- Iterates through the
- GetMultipleBetween(string[] stringArray, string start, string end, bool startEndIncluded):
- Searches through the
stringArray
, returning multiple instances found betweenstart
andend
. UsestartEndIncluded
if you want to includestart
andend
in the returning array.
- Searches through the
- KeepBetween(string[] stringArray, string start, string end, bool startEndIncluded, bool excludeEmptyIndexes):
- Iterates through the
stringArray
, keeping the content betweenstart
andend
. IfstartEndIncluded
is enabled, the indexes will keep thestart
andend
. IfexcludeEmptyIndexes
is enabled, empty indexes will be removed from the array.
- Iterates through the
- Exclude(string[] stringArray, string[] excludeStrings):
- Iterates through the
stringArray
, excluding the indexes that containexcludeStrings
.
- Iterates through the
- AddRange<T>(T[] currentArray, T[] arrayToAdd):
- Adds the
currentArray
intoarrayToAdd
.
- Adds the
BoolHelper:
- ToBool(string value, SearchType searchType, string[] trueValue, string[] falseValue):
- Tries to parse the
value
into abool
. If the conversion was successfull, it will returnvalue
astrue
orfalse
depending on where it was found (trueValues
,falseValues
). Ifvalue
is not found in any of those, it'll launch anArgumentOutOfRangeException
.
- Tries to parse the
CharHelper:
- ToChar(string value, int index):
- Converts the
value
into a char. If the length of value is higher than 1, it will return the first character of value or, ifindex
is passed, the character of the desiredindex
.
- Converts the
DictionaryHelper:
- ToDictionary<TKey, TValue>(List<string> list, string separator, bool invertKeyWithValue):
- Iterates through each element of the
list
and splits it byseparator
, assigningTKey
to everything that is before theseparator
andTValue
to everything that is after theseparator
.
- Iterates through each element of the
- FlipKeyWithValue<TKey, TValue>(Dictionary<TKey, TValue> dictionary):
- Returns the
dictionary
where theTValue
is the key andTKey
is the value.
- Returns the
DirectoryHelper:
- Exist(string path, bool createFolder):
- Checks if a
path
exists. IfcreateFolder
is true, it will create thepath
if it doesn't exist.
- Checks if a
- NotExist(string path, bool createFolder):
- Checks if a
path
does not exist. IfcreateFolder
is true, it will create thepath
if it doesn't exist.
- Checks if a
FileHelper:
- GetFileExtention(string fileName):
- Returns the extention of a
fileName
. If thefileName
multiple extentions (Example: filename.txt.zip), it will return the last extention.
- Returns the extention of a
- Exist(string fullFileName, bool createFile):
- Checks if
fullFileName
exists. IfcreateFile
is true, it will create thefullFileName
if it doesn't exist (Keep in mind that the path of thefullFileName
must exist forcreateFile
to work).
- Checks if
- NotExist(string fullFileName, bool createFile):
- Checks if
fullFileName
does not exist. IfcreateFile
is true, it will create thefullFileName
if it doesn't exist (Keep in mind that the path of thefullFileName
must exist forcreateFile
to work).
- Checks if
HtmlHelper:
- EncodeHtml(string decodedHtml):
- Converts a
decodedHtml
into a HTML-encoded string.
- Converts a
- DecodeHtml(string encodedHtml):
- Converts a
encodedHtml
into a decoded string.
- Converts a
- GetHrefLink(string html):
- Checks the
html
and tries to return the first link that is in between the href="".
- Checks the
- GetMultipleHrefLinks(string html):
- Checks the
html
and tries to return multiple links that are in between the href="".
- Checks the
- GetTable(string html):
- Checks the
html
and tries to return the first table that is in between the <table><\table>.
- Checks the
- GetMultipleTables(string html):
- Checks the
html
and tries to return multiple tables that are in between the <table><\table>.
- Checks the
- GetRowsFromTable(string htmlTable):
- Checks the
htmlTable
and tries to return the rows that are in between the <tr><\tr>.
- Checks the
- GetDataFromRows(string htmlTable):
- Checks the
htmlTable
and tries to return the data that are in between the <td><\td>.
- Checks the
- GetMultipleDataFromTables(List<string> htmlTables):
- Checks the
htmlTables
and tries to return all the data that are in multiple rows of multiple tables.
- Checks the
ListHelper:
- AddRange<T>(List<T> list, T[] array, int startIndex, int endIndex):
- Adds the
array
into thelist
. IfstatIndex
is specified, it will add the contents of thearray
only fromstartIndex
(included) until the end of the array or until it reachesendIndex
(included) if it is specified.
- Adds the
- AddRange<T>(List<T> list, List<T> listToAdd, int index):
- Adds the
listToAdd
into thelist
. Ifindex
is specified, it will add the contents of thelistToAdd
only fromindex
(included) until the end of the list.
- Adds the
- ToList<T>(T[] array):
- Transforms an
array
into a List<T>.
- Transforms an
- OrderByAscending(List<T> list):
- Orders a
list
in ascending order.
- Orders a
- OrderByDescending<T>(List<T> list):
- Orders a
list
in descending order.
- Orders a
- ToString<T>(List<T> list, string separator, int startIndex, int count)
- Converts an
list
into a single line of string. Ifseparator
is not passed, it will separate by a space. Examples: ListToString(new int[] { 1, 3, 5 }) → "1 3 5", ListToString(new string[] { "5", "2" }, "|") → "5|2".
- Converts an
- HasAny<T>(List<T> list)
- Iterates through the
list
, checking that it has at least 1 non null element.
- Iterates through the
- GetValueLike(List<string> list, string value, StringComparison stringComparison)
- Iterates through the
list
, returning the first item found that containsvalue
.
- Iterates through the
- GetValueContaining(List<string> list, StringComparison stringComparison, string[] values)
- Iterates through the
list
, returning the first item found that contains all thevalues
.
- Iterates through the
- AddToElements(List<string> list, string startItemTag, string endItemTag)
- Iterates through the
list
, addingstartItemTag
before the item andendItemTag
after the item. Example:startItemTag
is 'www.' and the items inside thelist
are 'google.com'. This method will return the elements as 'www.google.com'.
- Iterates through the
- RemoveFromElements(List<string> list, params string[] valuesToRemove)
- Returns a list where all occasions of
valuesToRemove
have been removed from the elements of thelist
.
- Returns a list where all occasions of
- ReplaceFromElements(List<string> list, string oldValue, string newValue)
- Returns a list where all occasions of
oldValue
have been replaced bynewValue
from the elements of thelist
.
- Returns a list where all occasions of
- GetBetween(List<string> stringList, string start, string end, bool startEndIncluded):
- Iterates through the
stringList
, returning the first instance where bothstart
andend
are found. If none of the indexes matchstart
andend
, astring.Empty
is returned. UsestartEndIncluded
if you want to includestart
andend
in the returning string.
- Iterates through the
- GetMultipleBetween(List<string> stringList, string start, string end, bool startEndIncluded):
- Searches through the
stringList
, returning multiple instances found betweenstart
andend
. UsestartEndIncluded
if you want to includestart
andend
in the returning List<string>.
- Searches through the
- KeepBetween(List<string> stringList, string start, string end, bool startEndIncluded, bool excludeEmptyIndexes):
- Iterates through the
stringList
, keeping the content betweenstart
andend
. IfstartEndIncluded
is enabled, the indexes will keep thestart
andend
. IfexcludeEmptyIndexes
is enabled, empty indexes will be removed from the list.
- Iterates through the
- Exclude(List<string> stringList, string[] excludeStrings):
- Iterates through the
stringList
, excluding the indexes that containexcludeStrings
.
- Iterates through the
- GetMultipleBetweenIndexes(List<string> stringList, string start, string end, bool startEndIncluded):
- Searches through the
stringList
, returningmultiple instances found betweenstart
andend
for each index. If you want only one instance per index, please use the methodGetMultipleBetween()
.
- Searches through the
- SplitListIntoSubLists<T>(List<T> currentList, int elementsPerSubList):
- Splits a generic list into multiple sublists based on the number of elements you want to split, represented by
elementsPerSubList
.
- Splits a generic list into multiple sublists based on the number of elements you want to split, represented by
MultiHelper:
- ClampValue<T>(T currentValue, T minValue, T maxValue):
- Clamps
currentValue
based on its' parameters. ReturnsmaxValue
ifcurrentValue
is higher than it and returnsminValue
if it is lower than it.
- Clamps
- AreNotNull<T>(params T[] objects):
- Checks if all
objects
are not null. If all ofobjects
are not null, returnstrue
. Otherwise returnsfalse
.
- Checks if all
- IsBetween<T>(T value, T minValue, T maxValue, bool inclusive):
- Checks if the
value
is in the range ofminValue
andmaxValue
. Settinginclusive
to true will also includeminValue
andmaxValue
in the verification.
- Checks if the
- IsEquivalentTo(Type type, Type[] validTypes):
- Determines whether
type
is equivalent to anyvalidTypes
.
- Determines whether
NumberHelper:
- ToDecimal(string value):
- Converts
value
into a decimal. If the conversion fails, returns a0.0M
.
- Converts
- ToDouble(string value):
- Converts
value
into a double. If the conversion fails, returns a0.0d
.
- Converts
- ToInt(string value):
- Converts
value
into a int. If the conversion fails, returns a0
.
- Converts
- Max<T>(T[] sequence):
- Returns the highest number present in the
sequence
.
- Returns the highest number present in the
- Min<T>(T[] sequence):
- Returns the lowest number present in the
sequence
.
- Returns the lowest number present in the
- IsNullOrZero<T>(T value):
- Checks if
value
is a null or 0.
- Checks if
StringHelper:
- GetBetween(string text, string start, string end, bool startEndIncluded):
- Searches through the
text
, returning the first instance found betweenstart
andend
. UsestartEndIncluded
if you want to includestart
andend
in the returning string.
- Searches through the
- GetMultipleBetween(string text, string startTag, string endTag, bool tagsIncluded):
- Searches through the
text
, returning multiple instances found betweenstart
andend
. UsestartEndIncluded
if you want to includestart
andend
in the returning List of string.
- Searches through the
- GetBetweenReverse(string text, string start, string end, bool startEndIncluded):
- Searches through the
text
, using thestart
as the end tag and then searches thetext
backwards until theend
tag is found.
- Searches through the
- AndContains(string text, StringComparison stringComparison, string[] values):
- Checks a
string
if it has all instances ofvalues
. If that's the case, then it returnstrue
, otherwise it returnsfalse
.
- Checks a
- OrContains(string text, StringComparison stringComparison, string[] values):
- Checks a
string
if it has at least one instance ofvalues
. If that's the case, then it returnstrue
, otherwise it returnsfalse
.
- Checks a
- IsEmpty(string value):
- Checks if the
value
isnull
,string.Empty
or a white space ("", " ", "\n", "\r", ...)
- Checks if the
- IsNotEmpty(string value):
- Check if the
value
contains any kind of character.
- Check if the
- AreEmpty(string[] values):
- Checks if all instances of
values
are null, string.Empty or a white space ("", " ", "\n", "\r", ...), returningtrue
if all of them are empty.
- Checks if all instances of
- AreNotEmpty(string[] values):
- Checks if all instances of
values
contain any kind of character, returningtrue
if all of them are not empty.
- Checks if all instances of
- LetterUpperCase(string value, int index):
- Changes a letter from
value
to be upper-case. Ifindex
is not passed, it will change the first letter ofvalue
.
- Changes a letter from
- LetterLowerCase(string value, int index):
- Changes a letter from
value
to be lower-case. Ifindex
is not passed, it will change the first letter ofvalue
.
- Changes a letter from
- Remove(string value, params string[] valuesToRemove):
- Returns a string where all instances of
valuesToRemove
have been removed from thevalue
.
- Returns a string where all instances of
- CharCount(string value, string valueToCount)
- Returns the count of
valueToCount
present in thevalue
.
- Returns the count of
- RemoveTags(string value, string[] tags)
- Returns a string where all instances of
tags
are removed fromvalue
(Example: Passing 'b' will remove all '<b>', '</b>' and <b/> xml tags).
- Returns a string where all instances of
- Reverse(string value)
- Reverses a string.
- Split(string value, string separator, bool keepSplitValue)
- Splits the
value
based on theseparator
. UsekeepSplitValue
to keep theseparator
on the values.
- Splits the
- SeparateByUpperCase(string value, string separator)
- Separates the
value
by upper-case characters.
- Separates the
- SeparateByLowerCase(string value, string separator)
- Separates the
value
by lower-case characters.
- Separates the
- GetUpperCaseLetters(string value, string separator)
- Reads the
value
, returning the present upper-case letters.
- Reads the
- GetLowerCaseLetters(string value, string separator)
- Reads the
value
, returning the present lower-case letters.
- Reads the
- SplitBy(string value, SplitType splitType, bool keepSeparator, string separator)
- Splits the
value
based on thesplitType
.
- Splits the
TTable:
- AddColumn(params string[] columnName):
- AddColumn(params TTable[] columnName):
- Adds a new
TTableColumn
in theTTable
.
- Adds a new
- RenameColumn(string currentColumnName, string newColumnname):
- Renames a column (if it exists).
- GetColumn(params TTable[] columnName):
- Returns an instance of
TTableColumn
if it is present inTTable.ColumnList
. If it is not present, returns a null.
- Returns an instance of
- GetColumns(int index):
- Returns all
TTableColumn
present inTTable.ColumnList
, or, ifindex
is passed, returns theTTableColumn
of the desiredindex
.
- Returns all
- MoveColumnIndex(TTableColumn tableColumn, int newIndex):
- MoveColumnIndex(string columnName, int newIndex)
- Moves a
tableColumn
's index tonewIndex
.
- Moves a
- RemoveColumn(params TTableColumn[] tableColumn):
- RemoveColumn(params string[] columnName)
- Removes a
tableColumn
fromTTable.ColumnList
(Method will useTTableColumn.ColumnName
to determine whichTTableColumn
to remove fromTTable.ColumnList
.
- Removes a
- AddData(string columnName, params object[] values):
- AddData(TTableColumn tableColumn, params object[] values):
- Adds
values
into theTTableColumn
asobject
.
- Adds
- ExistsData(string columnName, object value):
- ExistsData(TTableColumn tableColumn, object value):
- Checks through the
TTableColumn
forvalue
. Returnstrue
ifvalue
is found, otherwisefalse
.
- Checks through the
- GetData(string columnName):
- If the
columnName
exists, returns all the data present in theTTableColumn
.
- If the
- RemoveData(string columnName, params object[] valuesToRemove):
- RemoveData(TTableColumn tableColumn, params object[] valuesToRemove):
- Removes all instances of
valuesToRemove
.
- Removes all instances of
- TableToCsv(bool addHeader, string separator):
- Transform the
TTable
into a parseable.csv
file.
- Transform the
- CsvToTable(string fullFileName, string separator):
- Transform a
.csv
file into aTTable
.
- Transform a
TTableColumn:
- string ColumnName { get; set; }:
- Gets or sets the name of the column.
- List<object> ColumnData { get; set; }:
- Gets or sets the data in the column.
- AddData(params object[] values):
- Adds the values in the
ColumnData
asobject
.
- Adds the values in the
- ExistData(object value):
- Checks through the
ColumnData
forvalue
. Returnstrue
ifvalue
is found, otherwisefalse
.
- Checks through the
- RemoveData(params object[] values):
- Removes all instances of
values
.
- Removes all instances of
XmlHelper:
- RemoveEmptyTags(string xml):
- Searches through the
xml
, removing empty tags that have the format of <EmptyTag\>.
- Searches through the
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. 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 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. |
-
net5.0
- No dependencies.
-
net6.0
- No dependencies.
-
net7.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.
Version | Downloads | Last updated | |
---|---|---|---|
1.13.1 | 490 | 6/14/2023 | |
1.13.0 | 153 | 6/12/2023 | |
1.12.6 | 321 | 3/27/2023 | |
1.12.5 | 205 | 3/27/2023 | |
1.12.4 | 322 | 3/14/2023 | |
1.12.3 | 911 | 2/9/2023 | |
1.12.2 | 260 | 2/9/2023 | |
1.12.1 | 303 | 1/27/2023 | |
1.12.0 | 1,003 | 1/20/2023 | |
1.11.0 | 348 | 1/12/2023 | |
1.10.0 | 1,584 | 10/13/2022 | |
1.9.0 | 467 | 9/28/2022 | |
1.8.1 | 488 | 9/12/2022 | |
1.8.0 | 426 | 9/12/2022 | |
1.7.0 | 413 | 9/9/2022 | |
1.6.0 | 524 | 8/29/2022 | |
1.5.2 | 887 | 6/30/2022 | |
1.5.1 | 437 | 6/28/2022 | |
1.4.0 | 443 | 6/22/2022 | |
1.3.2 | 459 | 6/15/2022 | |
1.3.1 | 466 | 6/15/2022 | |
1.3.0 | 513 | 6/13/2022 | |
1.2.0 | 462 | 6/2/2022 | |
1.1.1 | 456 | 5/30/2022 | |
1.1.0 | 458 | 5/25/2022 | |
1.0.15 | 445 | 5/13/2022 | |
1.0.14 | 444 | 5/4/2022 | |
1.0.13 | 449 | 5/3/2022 | |
1.0.12 | 450 | 4/28/2022 | |
1.0.11 | 474 | 3/4/2022 | |
1.0.8 | 470 | 2/23/2022 | |
1.0.7 | 463 | 2/23/2022 | |
1.0.6 | 498 | 2/18/2022 | |
1.0.5 | 515 | 2/10/2022 | |
1.0.4 | 522 | 1/31/2022 | |
1.0.3 | 523 | 1/27/2022 | |
1.0.2 | 570 | 11/9/2021 | |
1.0.1 | 559 | 11/9/2021 |
DateTimeHelper:
- Re-introduced old DateTime helper class. Now it is under the TsadriuUtilitiesOld namespace. This will no longer be maintained, so consider using the TsadriuUtilities.DateTime library as this class will be removed soon from this library.
StringHelper:
- Now it is under the TsadriuUtilitiesOld namespace. This will no longer be maintained, so consider using the TsadriuUtilities.String library as this class will be removed soon from this library.