C# – Trim a UTF-8 string to the specified number of bytes

Here’s the simplest way to efficiently trim a UTF-8 string to the specified number of bytes: A UTF-8 string can have a mix of characters between 1 to 4 bytes. When you only take part of the byte array, you may end up cutting multi-byte chars in half, which then get replaced with the replacement … Read more

C# – Check if an IP range is valid

Given an IP range as a starting IP address and an ending IP address (as strings, like from user input or a config file), you can check if the IP range is valid by doing the following steps: Here’s an example. Let’s say you’re given starting IP “192.168.0.1” and ending “192.168.0.11”. The following table shows … Read more