Public static string filteroffutf8mb4_2 (string text) throws unsupportedencodingexception {byte [] bytes = text. getbytes ("UTF-8"); bytebuffer buffer = bytebuffer. allocate (bytes. length); int I = 0; while (I <bytes. length) {short B = bytes [I]; If (B> 0) {buffer. put (Bytes [I ++]); continue;} B + = 256; // remove the symbol bit if (B> 5) ^ 0b110) = 0) {buffer. put (bytes, I, 2); I + = 2; system. out. println ("2");} else if (B> 4) ^ 0b1110) = 0) {system. out. println ("3"); buffer. put (bytes, I, 3); I + = 3;} else if (B> 3) ^ 0b11110) = 0) {I + = 4; system. out. println ("4");} else if (B> 2) ^ 0b111110) = 0) {I ++ = 5; system. out. println ("5");} else if (B> 1) ^ 0b1111110) = 0) {I ++ = 6; system. out. println ("6");} else {buffer. put (Bytes [I ++]);} buffer. flip (); return new string (buffer. array (), "UTF-8 ");}
Filter UTF-8 characters with more than 3 bytes