Daily Archives: May 12, 2021

C# || How To Append & Join A Date & Time Value Together Using C#

The following is a module with functions which demonstrates how to append and join a date and time value together using C#.


1. Append Date & Time

The example below demonstrates the use of ‘Utils.Extensions.SetTime‘ to append a date and time value together.


2. Utils Namespace

The following is the Utils Namespace. Include this in your project to start using!


3. More Examples

Below are more examples demonstrating the use of the ‘Utils‘ Namespace. Don’t forget to include the module when running the examples!

QUICK NOTES:
The highlighted lines are sections of interest to look out for.

The code is heavily commented, so no further insight is necessary. If you have any questions, feel free to leave a comment below.

C# || How To Generate Hourly Time Range With Minute Interval Using C#

The following is a module with functions which demonstrates how to generate an hourly time range with minute interval between a start and end time using C#.

The function demonstrated in this page generates a time value list containing the time from a starting hour to an ending hour, separated by a minute step. The starting and ending hour is an integer from 0 through 23 representing the 24 hour period of the day, and the minute step can be any minute interval, including decimal values.

The starting and ending hours can also be flipped, indicating that the results should be returned in descending order.

An optional parameter also exists which allows to tune the results. When the range is in ascending order, the parameter indicates that the results should exclude/include the entire ending hour. When the range is in descending order, the parameter indicates that the results should exclude/include the entire starting hour.


1. Ascending Time Range – Minute Interval – Default

The example below demonstrates the use of ‘Utils.DateRange.GetTimeRange‘ to get the time range with a minute interval in ascending order.

In this example, the default options are used, which excludes the full ending hour from the results.


2. Descending Time Range – Hourly Interval – Default

The example below demonstrates the use of ‘Utils.DateRange.GetTimeRange‘ to get the time range with a hourly interval in descending order.

In this example, the default options are used, which excludes the full starting hour from the results.


3. Ascending Time Range – Minute Interval – Include Full Hour

The example below demonstrates the use of ‘Utils.DateRange.GetTimeRange‘ to get the time range with a minute interval in ascending order.

In this example, the optional parameter is used, which includes the full ending hour from the results.


4. Descending Time Range – Hourly Interval – Include Full Hour

The example below demonstrates the use of ‘Utils.DateRange.GetTimeRange‘ to get the time range with a hourly interval in descending order.

In this example, the optional parameter is used, which includes the full starting hour from the results.


5. Utils Namespace

The following is the Utils Namespace. Include this in your project to start using!


6. More Examples

Below are more examples demonstrating the use of the ‘Utils‘ Namespace. Don’t forget to include the module when running the examples!

QUICK NOTES:
The highlighted lines are sections of interest to look out for.

The code is heavily commented, so no further insight is necessary. If you have any questions, feel free to leave a comment below.

C# || How To Add & Use Custom Attributes To Class Properties Using C#

The following is a module with functions which demonstrates how to add and use custom attributes for class properties using C#.

The function demonstrated on this page is a generic extension method which uses reflection to get object property data transformed according to its custom attribute.


1. Custom Attribute

The example below demonstrates the use of ‘Utils.Extensions.GetPropertyData‘ to get object property data transformed according to its custom attribute.


2. Utils Namespace

The following is the Utils Namespace. Include this in your project to start using!


3. More Examples

Below are more examples demonstrating the use of the ‘Utils‘ Namespace. Don’t forget to include the module when running the examples!

QUICK NOTES:
The highlighted lines are sections of interest to look out for.

The code is heavily commented, so no further insight is necessary. If you have any questions, feel free to leave a comment below.

C# || How To Remove Excess Whitespace From A String Using C#

The following is a module with functions which demonstrates how to remove excess whitespace from a string, replacing multiple spaces into just one using C#.


1. Remove Excess Whitespace

The example below demonstrates the use of ‘Utils.Extensions.ToSingleSpace‘ to remove excess whitespace from a string.


2. Utils Namespace

The following is the Utils Namespace. Include this in your project to start using!


3. More Examples

Below are more examples demonstrating the use of the ‘Utils‘ Namespace. Don’t forget to include the module when running the examples!

QUICK NOTES:
The highlighted lines are sections of interest to look out for.

The code is heavily commented, so no further insight is necessary. If you have any questions, feel free to leave a comment below.

C# || How To Remove All Whitespace From A String Using C#

The following is a module with functions which demonstrates how to remove all whitespace from a string using C#.


1. Remove All Whitespace

The example below demonstrates the use of ‘Utils.Extensions.RemoveWhitespace‘ to remove all whitespace from a string.


2. Utils Namespace

The following is the Utils Namespace. Include this in your project to start using!


3. More Examples

Below are more examples demonstrating the use of the ‘Utils‘ Namespace. Don’t forget to include the module when running the examples!

QUICK NOTES:
The highlighted lines are sections of interest to look out for.

The code is heavily commented, so no further insight is necessary. If you have any questions, feel free to leave a comment below.

C# || How To Remove Non Alphanumeric Characters From A String Using C#

The following is a module with functions which demonstrates how to remove and replace non alphanumeric characters from a string using C#.


1. Alphanumeric Characters

The example below demonstrates the use of ‘Utils.Extensions.ToAlphaNumeric‘ to create an alphanumeric string.


2. Utils Namespace

The following is the Utils Namespace. Include this in your project to start using!


3. More Examples

Below are more examples demonstrating the use of the ‘Utils‘ Namespace. Don’t forget to include the module when running the examples!

QUICK NOTES:
The highlighted lines are sections of interest to look out for.

The code is heavily commented, so no further insight is necessary. If you have any questions, feel free to leave a comment below.

C# || How To Replace Entire Words In A String Using C#

The following is a module with functions which demonstrates how to replace entire words in a string using C#.

This function is different from String.Replace in that instead of replacing all substring instances in a word, it replaces all instances of matching entire words in a string.


1. Replace Entire Word

The example below demonstrates the use of ‘Utils.Extensions.ReplaceWord‘ to replace an entire word.


2. Utils Namespace

The following is the Utils Namespace. Include this in your project to start using!


3. More Examples

Below are more examples demonstrating the use of the ‘Utils‘ Namespace. Don’t forget to include the module when running the examples!

QUICK NOTES:
The highlighted lines are sections of interest to look out for.

The code is heavily commented, so no further insight is necessary. If you have any questions, feel free to leave a comment below.

C# || How To Manually Copy Two Streams From One To Another Using C#

The following is a module with functions which demonstrates how to manually copy two steams from one to another using C#.


1. Manually Copy Stream

The example below demonstrates the use of ‘Utils.Extensions.CopyStream‘ to copy two streams.


2. Utils Namespace

The following is the Utils Namespace. Include this in your project to start using!


3. More Examples

Below are more examples demonstrating the use of the ‘Utils‘ Namespace. Don’t forget to include the module when running the examples!

QUICK NOTES:
The highlighted lines are sections of interest to look out for.

The code is heavily commented, so no further insight is necessary. If you have any questions, feel free to leave a comment below.