Table of Contents

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

destinationEncodingCodepage int

Destination encoding codepage.

input List<byte>

Input bytes to convert.

badCharsReplaceFor string

Replacement 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

buffer byte[]

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

bom List<byte>

First 4 bytes of the file.

defaultEncoding Encoding

Default 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

path string

Path 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

characterCode int

Character 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

encoding Encoding

The encoding to print names for.

Returns

string

String containing all encoding names, one per line.