Class EncodingHelper
- Namespace
- SunamoFileIO
- Assembly
- SunamoFileIO.dll
Helper class for encoding detection and conversion operations.
public class EncodingHelper
- Inheritance
-
EncodingHelper
- Inherited Members
- Extension Methods
Methods
ConvertTo(int, List<byte>, string)
Converts bytes from detected encoding to specified destination encoding, replacing bad characters.
public static string ConvertTo(int destinationEncodingCodepage, List<byte> input, string badCharsReplaceFor)
Parameters
destinationEncodingCodepageintDestination encoding codepage.
inputList<byte>Input bytes to convert.
badCharsReplaceForstringReplacement string for characters that cannot be converted.
Returns
- string
Converted string in destination encoding.
ConvertToAllAvailableEncodings(byte[])
Converts bytes to all available encodings and returns a dictionary of codepage to converted string.
public static Dictionary<int, string> ConvertToAllAvailableEncodings(byte[] buffer)
Parameters
bufferbyte[]Bytes to convert.
Returns
- Dictionary<int, string>
Dictionary mapping codepage to converted string.
DetectEncoding(List<byte>, Encoding?)
Detects encoding from the first 4 bytes (BOM - Byte Order Mark).
public static Encoding DetectEncoding(List<byte> bom, Encoding? defaultEncoding = null)
Parameters
bomList<byte>First 4 bytes of the file.
defaultEncodingEncodingDefault encoding to return if no BOM detected (defaults to ASCII).
Returns
- Encoding
Detected encoding or default encoding.
IsBinary(string)
Checks if a file is binary by detecting control characters.
public static bool IsBinary(string path)
Parameters
pathstringPath to the file to check.
Returns
- bool
True if file contains control characters (binary), false otherwise.
IsControlChar(int)
Checks if a character is a control character (non-printable).
public static bool IsControlChar(int characterCode)
Parameters
characterCodeintCharacter code to check.
Returns
- bool
True if character is a control character, false otherwise.
PrintNamesForEncodingAsIsInSheet(Encoding)
Prints all encoding names for a given encoding (EncodingName, BodyName, HeaderName, WebName).
public static string PrintNamesForEncodingAsIsInSheet(Encoding encoding)
Parameters
encodingEncodingThe encoding to print names for.
Returns
- string
String containing all encoding names, one per line.