Search

How to Trim a UTF-8 string to the specified number of bytes in C#
By Tan Lee Published on Feb 05, 2025 295

To trim a UTF-8 string to a specified number of bytes in C#, you need to account for the fact that characters in UTF-8 encoding can vary in size, ranging from 1 to 4 bytes.

Read more
How to Save a list of strings to a file in C#
By Tan Lee Published on Feb 05, 2025 263

The simplest way to save a list of integers to a file is by using File.WriteAllLines().

Read more
How to Convert string list to float list in C#
By Tan Lee Published on Feb 05, 2025 333

You can convert a list of strings to a list of floating-point numbers using float.Parse() on all the strings.

Read more
How to Remove a list of characters from a string in C#
By Tan Lee Published on Feb 05, 2025 315

When you want to remove a list of characters from a string, you can loop through the list and use string.Replace():

Read more
How to Check if a string contains any substring from a list in C#
By Tan Lee Published on Feb 05, 2025 975

There are various use cases where you may need to verify whether a string contains any element from a list of substrings.

Read more
Find a character in a string in C#
By Tan Lee Published on Feb 05, 2025 230

There are several ways to find a character in a string in C#:

Read more
Remove non-alphanumeric characters from a string in C#
By Tan Lee Published on Feb 05, 2025 478

A simple approach to removing non-alphanumeric characters from a string is by utilizing a regular expression (regex):

Read more
Ignore case with string.Contains() in C#
By Tan Lee Published on Feb 05, 2025 198

By default, string.Contains() performs a case-sensitive search for a substring (or character) within a string.

Read more
Deserialize JSON using different property names in C#
By Tan Lee Published on Feb 05, 2025 789

When working with JSON data where property names don’t match your class property names, and you cannot alter the JSON or class structure, you have three main options to handle this discrepancy:

Read more
Deserialize JSON to a derived type in C#
By Tan Lee Published on Feb 05, 2025 578

To deserialize JSON into a derived type, you typically embed the type name in the JSON string. During deserialization, the system checks the type name against known derived types and deserializes it to the correct type.

Read more