What Do These "\E6##" Characters Mean

How does a file with Chinese characters know how many bytes to use per character?

If the encoding is UTF-8, then the following table shows how a Unicode code point (up to 21 bits) is converted into UTF-8 encoding:

Scalar Value                 1st Byte  2nd Byte  3rd Byte  4th Byte
00000000 0xxxxxxx 0xxxxxxx
00000yyy yyxxxxxx 110yyyyy 10xxxxxx
zzzzyyyy yyxxxxxx 1110zzzz 10yyyyyy 10xxxxxx
000uuuuu zzzzyyyy yyxxxxxx 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx

There are a number of non-allowed values - in particular, bytes 0xC1, 0xC2, and 0xF5 - 0xFF can never appear in well-formed UTF-8. There are also a number of other verboten combinations. The irregularities are in the 1st byte and 2nd byte columns. Note that the codes U+D800 - U+DFFF are reserved for UTF-16 surrogates and cannot appear in valid UTF-8.

Code Points          1st Byte  2nd Byte  3rd Byte  4th Byte
U+0000..U+007F 00..7F
U+0080..U+07FF C2..DF 80..BF
U+0800..U+0FFF E0 A0..BF 80..BF
U+1000..U+CFFF E1..EC 80..BF 80..BF
U+D000..U+D7FF ED 80..9F 80..BF
U+E000..U+FFFF EE..EF 80..BF 80..BF
U+10000..U+3FFFF F0 90..BF 80..BF 80..BF
U+40000..U+FFFFF F1..F3 80..BF 80..BF 80..BF
U+100000..U+10FFFF F4 80..8F 80..BF 80..BF

These tables are lifted from the Unicode standard version 5.1.


In the question, the material from offset 0x0010 .. 0x008F yields:

0x61           = U+0061
0x61 = U+0061
0x61 = U+0061
0xE6 0xBE 0xB3 = U+6FB3
0xE5 0xA4 0xA7 = U+5927
0xE5 0x88 0xA9 = U+5229
0xE4 0xBA 0x9A = U+4E9A
0xE4 0xB8 0xAD = U+4E2D
0xE6 0x96 0x87 = U+6587
0xE8 0xAE 0xBA = U+8BBA
0xE5 0x9D 0x9B = U+575B
0x2C = U+002C
0xE6 0xBE 0xB3 = U+6FB3
0xE6 0xB4 0xB2 = U+6D32
0xE8 0xAE 0xBA = U+8BBA
0xE5 0x9D 0x9B = U+575B
0x2C = U+002C
0xE6 0xBE 0xB3 = U+6FB3
0xE6 0xB4 0xB2 = U+6D32
0xE6 0x96 0xB0 = U+65B0
0xE9 0x97 0xBB = U+95FB
0x2C = U+002C
0xE6 0xBE 0xB3 = U+6FB3
0xE6 0xB4 0xB2 = U+6D32
0xE4 0xB8 0xAD = U+4E2D
0xE6 0x96 0x87 = U+6587
0xE7 0xBD 0x91 = U+7F51
0xE7 0xAB 0x99 = U+7AD9
0x2C = U+002C
0xE6 0xBE 0xB3 = U+6FB3
0xE5 0xA4 0xA7 = U+5927
0xE5 0x88 0xA9 = U+5229
0xE4 0xBA 0x9A = U+4E9A
0xE6 0x9C 0x80 = U+6700
0xE5 0xA4 0xA7 = U+5927
0xE7 0x9A 0x84 = U+7684
0xE5 0x8D 0x8E = U+534E
0x2D = U+002D
0x29 = U+0029
0xE5 0xA5 0xA5 = U+5965
0xE5 0xB0 0xBA = U+5C3A
0xE7 0xBD 0x91 = U+7F51
0x26 = U+0026
0x6C = U+006C
0x74 = U+0074
0x3B = U+003B

What character to use to put an item at the end of an alphabetic list?

I found this thread while wanting folders that sort after Z in Finder on Mac OSX. After several false paths and trial and error, here's what I found:

Characters that sort after Z in Finder (in sort-order)

  • z Lower case Z
  • ι Greek letter
  • Ι Greek letter, capital version of above character, not an "I")
  • Ω Omega
  • 一 Japanese Character? (Thanks, Jam)
  • 口 Japanese character? (Thanks, Jam)
  • 末 Japanese character "End" (Thanks, Jam)
  •  (a private use character) (Thanks, Peter O.)

These are characters others here and in other places on the web, mentioned sort after Z, but that I found DO NOT sort at the end, at least when sorting by name in Finder on Mac:

† ∆ ~ - ſ [ ø ■ |

wrong utf-8 characters when writing to file (python)

When you see in the text file something like Ê (or more generally 2 characters the first of which is Ã) it is likely that the file was correctly written in UTF8, and that the editor (or the screen) does not process correctly UTF8.

Let's look at æ. It is the unicode character U+E6. When you encode it in utf8, it gives the two characters b'\xc3\xa6' and when decoded as latin1 it printf 'æ'.

What can you do to confirm? Use the excellent vim editor that knows about multiple encoding and among others utf8, at least when you use its graphical interface gvim.

And just another general advice: never write non ascii characters in a python source file, unless you put a # -*- coding: ... -*- line as first line (or second if first is a hashbang one #! /usr/bin/env python)

And if you want to use unicode under Windows with Python, do use IDLE that natively processes it.

TL/DR: If you are using Linux, it is likely that your system is configured natively to use utf8 encoding, and you correctly write your text files in utf8 but your text editor just fails to display utf8 correctly

Regular expression to match a line that doesn't contain a word

The notion that regex doesn't support inverse matching is not entirely true. You can mimic this behavior by using negative look-arounds:

^((?!hede).)*$

Non-capturing variant:

^(?:(?!:hede).)*$

The regex above will match any string, or line without a line break, not containing the (sub)string 'hede'. As mentioned, this is not something regex is "good" at (or should do), but still, it is possible.

And if you need to match line break chars as well, use the DOT-ALL modifier (the trailing s in the following pattern):

/^((?!hede).)*$/s

or use it inline:

/(?s)^((?!hede).)*$/

(where the /.../ are the regex delimiters, i.e., not part of the pattern)

If the DOT-ALL modifier is not available, you can mimic the same behavior with the character class [\s\S]:

/^((?!hede)[\s\S])*$/

Explanation

A string is just a list of n characters. Before, and after each character, there's an empty string. So a list of n characters will have n+1 empty strings. Consider the string "ABhedeCD":

    ┌──┬───┬──┬───┬──┬───┬──┬───┬──┬───┬──┬───┬──┬───┬──┬───┬──┐
S = │e1│ A │e2│ B │e3│ h │e4│ e │e5│ d │e6│ e │e7│ C │e8│ D │e9│
└──┴───┴──┴───┴──┴───┴──┴───┴──┴───┴──┴───┴──┴───┴──┴───┴──┘

index 0 1 2 3 4 5 6 7

where the e's are the empty strings. The regex (?!hede). looks ahead to see if there's no substring "hede" to be seen, and if that is the case (so something else is seen), then the . (dot) will match any character except a line break. Look-arounds are also called zero-width-assertions because they don't consume any characters. They only assert/validate something.

So, in my example, every empty string is first validated to see if there's no "hede" up ahead, before a character is consumed by the . (dot). The regex (?!hede). will do that only once, so it is wrapped in a group, and repeated zero or more times: ((?!hede).)*. Finally, the start- and end-of-input are anchored to make sure the entire input is consumed: ^((?!hede).)*$

As you can see, the input "ABhedeCD" will fail because on e3, the regex (?!hede) fails (there is "hede" up ahead!).

\d less efficient than [0-9]

\d checks all Unicode digits, while [0-9] is limited to these 10 characters. For example, Persian digits, ۱۲۳۴۵۶۷۸۹, are an example of Unicode digits which are matched with \d, but not [0-9].

You can generate a list of all such characters using the following code:

var sb = new StringBuilder();
for(UInt16 i = 0; i < UInt16.MaxValue; i++)
{
string str = Convert.ToChar(i).ToString();
if (Regex.IsMatch(str, @"\d"))
sb.Append(str);
}
Console.WriteLine(sb.ToString());

Which generates:

0123456789٠١٢٣٤٥٦٧٨٩۰۱۲۳۴۵۶۷۸۹߀߁߂߃߄߅߆߇߈߉०१२३४५६७८९০১২৩৪৫৬৭৮৯੦੧੨੩੪੫੬੭੮੯૦૧૨૩૪૫૬૭૮૯୦୧୨୩୪୫୬୭୮୯௦௧௨௩௪௫௬௭௮௯౦౧౨౩౪౫౬౭౮౯೦೧೨೩೪೫೬೭೮೯൦൧൨൩൪൫൬൭൮൯๐๑๒๓๔๕๖๗๘๙໐໑໒໓໔໕໖໗໘໙༠༡༢༣༤༥༦༧༨༩၀၁၂၃၄၅၆၇၈၉႐႑႒႓႔႕႖႗႘႙០១២៣៤៥៦៧៨៩᠐᠑᠒᠓᠔᠕᠖᠗᠘᠙᥆᥇᥈᥉᥊᥋᥌᥍᥎᥏᧐᧑᧒᧓᧔᧕᧖᧗᧘᧙᭐᭑᭒᭓᭔᭕᭖᭗᭘᭙᮰᮱᮲᮳᮴᮵᮶᮷᮸᮹᱀᱁᱂᱃᱄᱅᱆᱇᱈᱉᱐᱑᱒᱓᱔᱕᱖᱗᱘᱙꘠꘡꘢꘣꘤꘥꘦꘧꘨꘩꣐꣑꣒꣓꣔꣕꣖꣗꣘꣙꤀꤁꤂꤃꤄꤅꤆꤇꤈꤉꩐꩑꩒꩓꩔꩕꩖꩗꩘꩙0123456789

How to insert a character every nth character in a pandas dataframe column

Let us try findall with map (.. means N = 2)

df.mac_address.str.findall('..').map(':'.join)
Out[368]:
0 00;03;E6;A5;84;C2
1 00;03;E6;A5;84;CC
2 00;03;E6;A5;84;DA
3 00;03;E6;A5;84;DC
4 00;03;E6;A5;84;E4
Name: mac_address, dtype: object

How to print the extended ASCII code in java from integer value

ASCII 153 (0x99) is different from Unicode U+0099 (Control character).

Solution

This program should do what you intend it to do:

public class ExtendedAscii {
public static final char[] EXTENDED = { 0x00C7, 0x00FC, 0x00E9, 0x00E2,
0x00E4, 0x00E0, 0x00E5, 0x00E7, 0x00EA, 0x00EB, 0x00E8, 0x00EF,
0x00EE, 0x00EC, 0x00C4, 0x00C5, 0x00C9, 0x00E6, 0x00C6, 0x00F4,
0x00F6, 0x00F2, 0x00FB, 0x00F9, 0x00FF, 0x00D6, 0x00DC, 0x00A2,
0x00A3, 0x00A5, 0x20A7, 0x0192, 0x00E1, 0x00ED, 0x00F3, 0x00FA,
0x00F1, 0x00D1, 0x00AA, 0x00BA, 0x00BF, 0x2310, 0x00AC, 0x00BD,
0x00BC, 0x00A1, 0x00AB, 0x00BB, 0x2591, 0x2592, 0x2593, 0x2502,
0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557,
0x255D, 0x255C, 0x255B, 0x2510, 0x2514, 0x2534, 0x252C, 0x251C,
0x2500, 0x253C, 0x255E, 0x255F, 0x255A, 0x2554, 0x2569, 0x2566,
0x2560, 0x2550, 0x256C, 0x2567, 0x2568, 0x2564, 0x2565, 0x2559,
0x2558, 0x2552, 0x2553, 0x256B, 0x256A, 0x2518, 0x250C, 0x2588,
0x2584, 0x258C, 0x2590, 0x2580, 0x03B1, 0x00DF, 0x0393, 0x03C0,
0x03A3, 0x03C3, 0x00B5, 0x03C4, 0x03A6, 0x0398, 0x03A9, 0x03B4,
0x221E, 0x03C6, 0x03B5, 0x2229, 0x2261, 0x00B1, 0x2265, 0x2264,
0x2320, 0x2321, 0x00F7, 0x2248, 0x00B0, 0x2219, 0x00B7, 0x221A,
0x207F, 0x00B2, 0x25A0, 0x00A0 };

public static final char getAscii(int code) {
if (code >= 0x80 && code <= 0xFF) {
return EXTENDED[code - 0x7F];
}
return (char) code;
}

public static final void printChar(int code) {
System.out.printf("%c%n", getAscii(code));
}

public static void main(String[] args) {
printChar(153);
printChar(63);
}
}

Output:

Ü

?

As you can see from the output above, the intended character gets printed correctly.


Extension of Concept

Also, I wrote a program that prints out the Unicode values for the extended Ascii. As you can see in the output below, a lot of characters have trouble being displayed as native char.

Code:

public class ExtendedAscii {
public static final char[] EXTENDED = { 0x00C7, 0x00FC, 0x00E9, 0x00E2,
0x00E4, 0x00E0, 0x00E5, 0x00E7, 0x00EA, 0x00EB, 0x00E8, 0x00EF,
0x00EE, 0x00EC, 0x00C4, 0x00C5, 0x00C9, 0x00E6, 0x00C6, 0x00F4,
0x00F6, 0x00F2, 0x00FB, 0x00F9, 0x00FF, 0x00D6, 0x00DC, 0x00A2,
0x00A3, 0x00A5, 0x20A7, 0x0192, 0x00E1, 0x00ED, 0x00F3, 0x00FA,
0x00F1, 0x00D1, 0x00AA, 0x00BA, 0x00BF, 0x2310, 0x00AC, 0x00BD,
0x00BC, 0x00A1, 0x00AB, 0x00BB, 0x2591, 0x2592, 0x2593, 0x2502,
0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557,
0x255D, 0x255C, 0x255B, 0x2510, 0x2514, 0x2534, 0x252C, 0x251C,
0x2500, 0x253C, 0x255E, 0x255F, 0x255A, 0x2554, 0x2569, 0x2566,
0x2560, 0x2550, 0x256C, 0x2567, 0x2568, 0x2564, 0x2565, 0x2559,
0x2558, 0x2552, 0x2553, 0x256B, 0x256A, 0x2518, 0x250C, 0x2588,
0x2584, 0x258C, 0x2590, 0x2580, 0x03B1, 0x00DF, 0x0393, 0x03C0,
0x03A3, 0x03C3, 0x00B5, 0x03C4, 0x03A6, 0x0398, 0x03A9, 0x03B4,
0x221E, 0x03C6, 0x03B5, 0x2229, 0x2261, 0x00B1, 0x2265, 0x2264,
0x2320, 0x2321, 0x00F7, 0x2248, 0x00B0, 0x2219, 0x00B7, 0x221A,
0x207F, 0x00B2, 0x25A0, 0x00A0 };

public static void main(String[] args) {
for (char c : EXTENDED) {
System.out.printf("%s, ", new String(Character.toChars(c)));
}
}
}

Output:

Ç, ü, é, â, ä, à, å, ç, ê, ë, è, ï, î, ì, Ä, Å, É, æ, Æ, ô, ö, ò, û, ù, ÿ, Ö, Ü, ¢, £, ¥, ?, ƒ, á, í, ó, ú, ñ, Ñ, ª, º, ¿, ?, ¬, ½, ¼, ¡, «, », ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ß, ?, ?, ?, ?, µ, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ±, ?, ?, ?, ?, ÷, ?, °, ?, ·, ?, ?, ², ?,  ,

Reference Table: (source)

Dec Hex Unicode     Char    Description
--- --- -------   ----   -----------------------------------
128 80 U+00C7 Ç latin capital letter c with cedilla
129 81 U+00FC ü latin small letter u with diaeresis
130 82 U+00E9 é latin small letter e with acute
131 83 U+00E2 â latin small letter a with circumflex
132 84 U+00E4 ä latin small letter a with diaeresis
133 85 U+00E0 à latin small letter a with grave
134 86 U+00E5 å latin small letter a with ring above
135 87 U+00E7 ç latin small letter c with cedilla
136 88 U+00EA ê latin small letter e with circumflex
137 89 U+00EB ë latin small letter e with diaeresis
138 8A U+00E8 è latin small letter e with grave
139 8B U+00EF ï latin small letter i with diaeresis
140 8C U+00EE î latin small letter i with circumflex
141 8D U+00EC ì latin small letter i with grave
142 8E U+00C4 Ä latin capital letter a with diaeresis
143 8F U+00C5 Å latin capital letter a with ring above
144 90 U+00C9 É latin capital letter e with acute
145 91 U+00E6 æ latin small ligature ae
146 92 U+00C6 Æ latin capital ligature ae
147 93 U+00F4 ô latin small letter o with circumflex
148 94 U+00F6 ö latin small letter o with diaeresis
149 95 U+00F2 ò latin small letter o with grave
150 96 U+00FB û latin small letter u with circumflex
151 97 U+00F9 ù latin small letter u with grave
152 98 U+00FF ÿ latin small letter y with diaeresis
153 99 U+00D6 Ö latin capital letter o with diaeresis
154 9A U+00DC Ü latin capital letter u with diaeresis
155 9B U+00A2 ¢ cent sign
156 9C U+00A3 £ pound sign
157 9D U+00A5 ¥ yen sign
158 9E U+20A7 ₧ peseta sign
159 9F U+0192 ƒ latin small letter f with hook
160 A0 U+00E1 á latin small letter a with acute
161 A1 U+00ED í latin small letter i with acute
162 A2 U+00F3 ó latin small letter o with acute
163 A3 U+00FA ú latin small letter u with acute
164 A4 U+00F1 ñ latin small letter n with tilde
165 A5 U+00D1 Ñ latin capital letter n with tilde
166 A6 U+00AA ª feminine ordinal indicator
167 A7 U+00BA º masculine ordinal indicator
168 A8 U+00BF ¿ inverted question mark
169 A9 U+2310 ⌐ reversed not sign
170 AA U+00AC ¬ not sign
171 AB U+00BD ½ vulgar fraction one half
172 AC U+00BC ¼ vulgar fraction one quarter
173 AD U+00A1 ¡ inverted exclamation mark
174 AE U+00AB « left-pointing double angle quotation mark
175 AF U+00BB » right-pointing double angle quotation mark
176 B0 U+2591 ░ light shade
177 B1 U+2592 ▒ medium shade
178 B2 U+2593 ▓ dark shade
179 B3 U+2502 │ box drawings light vertical
180 B4 U+2524 ┤ box drawings light vertical and left
181 B5 U+2561 ╡ box drawings vertical single and left double
182 B6 U+2562 ╢ box drawings vertical double and left single
183 B7 U+2556 ╖ box drawings down double and left single
184 B8 U+2555 ╕ box drawings down single and left double
185 B9 U+2563 ╣ box drawings double vertical and left
186 BA U+2551 ║ box drawings double vertical
187 BB U+2557 ╗ box drawings double down and left
188 BC U+255D ╝ box drawings double up and left
189 BD U+255C ╜ box drawings up double and left single
190 BE U+255B ╛ box drawings up single and left double
191 BF U+2510 ┐ box drawings light down and left
192 C0 U+2514 └ box drawings light up and right
193 C1 U+2534 ┴ box drawings light up and horizontal
194 C2 U+252C ┬ box drawings light down and horizontal
195 C3 U+251C ├ box drawings light vertical and right
196 C4 U+2500 ─ box drawings light horizontal
197 C5 U+253C ┼ box drawings light vertical and horizontal
198 C6 U+255E ╞ box drawings vertical single and right double
199 C7 U+255F ╟ box drawings vertical double and right single
200 C8 U+255A ╚ box drawings double up and right
201 C9 U+2554 ╔ box drawings double down and right
202 CA U+2569 ╩ box drawings double up and horizontal
203 CB U+2566 ╦ box drawings double down and horizontal
204 CC U+2560 ╠ box drawings double vertical and right
205 CD U+2550 ═ box drawings double horizontal
206 CE U+256C ╬ box drawings double vertical and horizontal
207 CF U+2567 ╧ box drawings up single and horizontal double
208 D0 U+2568 ╨ box drawings up double and horizontal single
209 D1 U+2564 ╤ box drawings down single and horizontal double
210 D2 U+2565 ╥ box drawings down double and horizontal single
211 D3 U+2559 ╙ box drawings up double and right single
212 D4 U+2558 ╘ box drawings up single and right double
213 D5 U+2552 ╒ box drawings down single and right double
214 D6 U+2553 ╓ box drawings down double and right single
215 D7 U+256B ╫ box drawings vertical double and horizontal single
216 D8 U+256A ╪ box drawings vertical single and horizontal double
217 D9 U+2518 ┘ box drawings light up and left
218 DA U+250C ┌ box drawings light down and right
219 DB U+2588 █ full block
220 DC U+2584 ▄ lower half block
221 DD U+258C ▌ left half block
222 DE U+2590 ▐ right half block
223 DF U+2580 ▀ upper half block
224 E0 U+03B1 α greek small letter alpha
225 E1 U+00DF ß latin small letter sharp s
226 E2 U+0393 Γ greek capital letter gamma
227 E3 U+03C0 π greek small letter pi
228 E4 U+03A3 Σ greek capital letter sigma
229 E5 U+03C3 σ greek small letter sigma
230 E6 U+00B5 µ micro sign
231 E7 U+03C4 τ greek small letter tau
232 E8 U+03A6 Φ greek capital letter phi
233 E9 U+0398 Θ greek capital letter theta
234 EA U+03A9 Ω greek capital letter omega
235 EB U+03B4 δ greek small letter delta
236 EC U+221E ∞ infinity
237 ED U+03C6 φ greek small letter phi
238 EE U+03B5 ε greek small letter epsilon
239 EF U+2229 ∩ intersection
240 F0 U+2261 ≡ identical to
241 F1 U+00B1 ± plus-minus sign
242 F2 U+2265 ≥ greater-than or equal to
243 F3 U+2264 ≤ less-than or equal to
244 F4 U+2320 ⌠ top half integral
245 F5 U+2321 ⌡ bottom half integral
246 F6 U+00F7 ÷ division sign
247 F7 U+2248 ≈ almost equal to
248 F8 U+00B0 ° degree sign
249 F9 U+2219 ∙ bullet operator
250 FA U+00B7 · middle dot
251 FB U+221A √ square root
252 FC U+207F ⁿ superscript latin small letter n
253 FD U+00B2 ² superscript two
254 FE U+25A0 ■ black square
255 FF U+00A0 no-break space


Related Topics



Leave a reply



Submit