Quick Tip : List available encodings

Here is a way to list the available encodings for a version of the .NET Framework


using System.Text;

 


EncodingInfo[] encodings = Encoding.GetEncodings();

Here is a piece of code to output the encoding info in an html file (as a table for readability)


var encodings = (from e in Encoding.GetEncodings()
 orderby e.Name
 select string.Format("<tr><td>{0}</td><td>{1}</td><td>{2}</td></tr>", e.CodePage, e.Name, e.DisplayName)
 ).ToList();

// add html part infos
 encodings.Insert(0, "<html><head><title>Encodings</title><style>table {width:100%;} table tr:nth-child(2n){background:#ddd;}</style></head><body><h1>Encodings list</h1><table><tr><th>Code</th><th>Name</th><th>DisplayName</th></tr>");
 encodings.Add("</table></body></html>");
 File.WriteAllLines(@"c:\encodings.html", encodings);

The result for the .NET FX 4.5 :

CodeNameDisplayName
708ASMO-708Arabic (ASMO 708)
950big5Chinese Traditional (Big5)
21025cp1025IBM EBCDIC (Cyrillic Serbian-Bulgarian)
866cp866Cyrillic (DOS)
875cp875IBM EBCDIC (Greek Modern)
50221csISO2022JPJapanese (JIS-Allow 1 byte Kana)
720DOS-720Arabic (DOS)
862DOS-862Hebrew (DOS)
51936EUC-CNChinese Simplified (EUC)
51932euc-jpJapanese (EUC)
20932EUC-JPJapanese (JIS 0208-1990 and 0212-1990)
51949euc-krKorean (EUC)
54936GB18030Chinese Simplified (GB18030)
936gb2312Chinese Simplified (GB2312)
52936hz-gb-2312Chinese Simplified (HZ)
858IBM00858OEM Multilingual Latin I
20924IBM00924IBM Latin-1
1047IBM01047IBM Latin-1
1140IBM01140IBM EBCDIC (US-Canada-Euro)
1141IBM01141IBM EBCDIC (Germany-Euro)
1142IBM01142IBM EBCDIC (Denmark-Norway-Euro)
1143IBM01143IBM EBCDIC (Finland-Sweden-Euro)
1144IBM01144IBM EBCDIC (Italy-Euro)
1145IBM01145IBM EBCDIC (Spain-Euro)
1146IBM01146IBM EBCDIC (UK-Euro)
1147IBM01147IBM EBCDIC (France-Euro)
1148IBM01148IBM EBCDIC (International-Euro)
1149IBM01149IBM EBCDIC (Icelandic-Euro)
37IBM037IBM EBCDIC (US-Canada)
1026IBM1026IBM EBCDIC (Turkish Latin-5)
20273IBM273IBM EBCDIC (Germany)
20277IBM277IBM EBCDIC (Denmark-Norway)
20278IBM278IBM EBCDIC (Finland-Sweden)
20280IBM280IBM EBCDIC (Italy)
20284IBM284IBM EBCDIC (Spain)
20285IBM285IBM EBCDIC (UK)
20290IBM290IBM EBCDIC (Japanese katakana)
20297IBM297IBM EBCDIC (France)
20420IBM420IBM EBCDIC (Arabic)
20423IBM423IBM EBCDIC (Greek)
20424IBM424IBM EBCDIC (Hebrew)
437IBM437OEM United States
500IBM500IBM EBCDIC (International)
737ibm737Greek (DOS)
775ibm775Baltic (DOS)
850ibm850Western European (DOS)
852ibm852Central European (DOS)
855IBM855OEM Cyrillic
857ibm857Turkish (DOS)
860IBM860Portuguese (DOS)
861ibm861Icelandic (DOS)
863IBM863French Canadian (DOS)
864IBM864Arabic (864)
865IBM865Nordic (DOS)
869ibm869Greek, Modern (DOS)
870IBM870IBM EBCDIC (Multilingual Latin-2)
20871IBM871IBM EBCDIC (Icelandic)
20880IBM880IBM EBCDIC (Cyrillic Russian)
20905IBM905IBM EBCDIC (Turkish)
20838IBM-ThaiIBM EBCDIC (Thai)
50220iso-2022-jpJapanese (JIS)
50222iso-2022-jpJapanese (JIS-Allow 1 byte Kana – SO/SI)
50225iso-2022-krKorean (ISO)
28591iso-8859-1Western European (ISO)
28603iso-8859-13Estonian (ISO)
28605iso-8859-15Latin 9 (ISO)
28592iso-8859-2Central European (ISO)
28593iso-8859-3Latin 3 (ISO)
28594iso-8859-4Baltic (ISO)
28595iso-8859-5Cyrillic (ISO)
28596iso-8859-6Arabic (ISO)
28597iso-8859-7Greek (ISO)
28598iso-8859-8Hebrew (ISO-Visual)
38598iso-8859-8-iHebrew (ISO-Logical)
28599iso-8859-9Turkish (ISO)
1361JohabKorean (Johab)
20866koi8-rCyrillic (KOI8-R)
21866koi8-uCyrillic (KOI8-U)
949ks_c_5601-1987Korean
10000macintoshWestern European (Mac)
932shift_jisJapanese (Shift-JIS)
20127us-asciiUS-ASCII
1200utf-16Unicode
1201utf-16BEUnicode (Big-Endian)
12000utf-32Unicode (UTF-32)
12001utf-32BEUnicode (UTF-32 Big-Endian)
65000utf-7Unicode (UTF-7)
65001utf-8Unicode (UTF-8)
1250windows-1250Central European (Windows)
1251windows-1251Cyrillic (Windows)
1252Windows-1252Western European (Windows)
1253windows-1253Greek (Windows)
1254windows-1254Turkish (Windows)
1255windows-1255Hebrew (Windows)
1256windows-1256Arabic (Windows)
1257windows-1257Baltic (Windows)
1258windows-1258Vietnamese (Windows)
874windows-874Thai (Windows)
20000x-Chinese-CNSChinese Traditional (CNS)
20002x-Chinese-EtenChinese Traditional (Eten)
20001x-cp20001TCA Taiwan
20003x-cp20003IBM5550 Taiwan
20004x-cp20004TeleText Taiwan
20005x-cp20005Wang Taiwan
20261x-cp20261T.61
20269x-cp20269ISO-6937
20936x-cp20936Chinese Simplified (GB2312-80)
20949x-cp20949Korean Wansung
50227x-cp50227Chinese Simplified (ISO-2022)
20833x-EBCDIC-KoreanExtendedIBM EBCDIC (Korean Extended)
29001x-EuropaEuropa
20105x-IA5Western European (IA5)
20106x-IA5-GermanGerman (IA5)
20108x-IA5-NorwegianNorwegian (IA5)
20107x-IA5-SwedishSwedish (IA5)
57006x-iscii-asISCII Assamese
57003x-iscii-beISCII Bengali
57002x-iscii-deISCII Devanagari
57010x-iscii-guISCII Gujarati
57008x-iscii-kaISCII Kannada
57009x-iscii-maISCII Malayalam
57007x-iscii-orISCII Oriya
57011x-iscii-paISCII Punjabi
57004x-iscii-taISCII Tamil
57005x-iscii-teISCII Telugu
10004x-mac-arabicArabic (Mac)
10029x-mac-ceCentral European (Mac)
10008x-mac-chinesesimpChinese Simplified (Mac)
10002x-mac-chinesetradChinese Traditional (Mac)
10082x-mac-croatianCroatian (Mac)
10007x-mac-cyrillicCyrillic (Mac)
10006x-mac-greekGreek (Mac)
10005x-mac-hebrewHebrew (Mac)
10079x-mac-icelandicIcelandic (Mac)
10001x-mac-japaneseJapanese (Mac)
10003x-mac-koreanKorean (Mac)
10010x-mac-romanianRomanian (Mac)
10021x-mac-thaiThai (Mac)
10081x-mac-turkishTurkish (Mac)
10017x-mac-ukrainianUkrainian (Mac)

Incoming search terms:

  • scumitz koi8
  • terminal available encodings list
  • Available encodings list

Quick tip : Master-Child checkboxes with jQuery

Here is a code that is really often asked.

I was asked how to code a master-child checkboxes using jQuery.

The requirements were :

  1. We want a “master” checkbox that the “child” checkboxes will mimic.
  2. We want this checkbox to be cheched if all child checkboxes are checked.
  3. We want this checkbox to be unchecked if all child checkboxes are not checked anymore.

Here is what I came with (check the demo here):

HTML markup :


<label>
 <input type="checkbox" id="checkall" />
 ALL</label>
 <hr />
 <div id="checkboxes">

<label>
 <input type="checkbox" />
 test 1</label><br />
 <label>
 <input type="checkbox" />
 test 2</label><br />
 <label>
 <input type="checkbox" />
 test 3</label><br />
 <label>
 </div>

jQuery part for requirement 1 :


$("#checkall").on("change", function () {
 $('#checkboxes input[type="checkbox"]').prop("checked", $(this).is(":checked"));
 });

Set all the checkboxes inside elements with class “checkboxes” to the value of the input with id “checkall”

jQuery part for requirements 2 and 3 :


$('#checkboxes [type="checkbox"]').on("change", function () {
 $("#checkall").prop("checked", $('#checkboxes input[type="checkbox"]:checked').length === $('#checkboxes input[type="checkbox"]').length);
 });

Set the element with id “checkall” to the answer to the question “is the number of checkboxes equal to the number of checked checkboxes”

You can check the demo here

Quick tip : redirect the console output to a file

In a console application, we use a lot the Console.WriteLine method.

We can redirect the output of the WriteLine method easily :


var consoleOut = Console.Out; // save the current output stream to be able to re-use it later

Console.SetOut(File.CreateText(@"C:\consoleout.txt")); // change the output stream for a file
 Console.WriteLine("a sample text"); // write some information

Console.SetOut(consoleOut); // reset the output to the console.