Cory Posted May 21, 2011 Report Share Posted May 21, 2011 For some time now I've dealt with the shortcoming in MEP that it can't deal with Unicode and relies completely on ASCII. But often I would have output from PowerShell or other thing that was Unicode and had given up. Today I was dealing with log files from NTBackup and slapping my forehead again when I had a closer look and discovered a quick and dirt way to convert the Unicode to ASCII with a few lines of MEP macro code if it's essentially ASCII text! Unicode was the solution to the problem of too limited of a character set for displaying many foreign languages and such. ASCII is 1 byte per letter but Unicode is 2 in UTF-16 and 4 in UTF-32. But get this... When the character is essentially an ASCII character like "A" the first byte is the usual ASCII value and the second is null (0x00 or 00000000). Now in some text files they add a byte order mark at the beginning which for UTF-16 looks like ÿþ or a couple of squares in a text box but is actually FF FE. Just be aware that in some instances it doesn’t exist and UTF-32 might be something like 00 00 FF FE. Variable Modify String %File Contents%: Delete a substring starting at 1 and 2 characters long // Remove header Variable Set Integer %Null Count% to the length of variable %File Contents% // Get the total number of bytes Variable Modify Integer: %Null Count% = %Null Count% / 2 // Cut in half Repeat Start (Repeat %Null Count% times) // Go thru each null Variable Modify String %File Contents%: Delete a substring starting at %Position% and 1 characters long // Delete Null byte End Repeat In this example I have inducted the Unicode string into a text variable, deleted the first two bytes (FF FE) as in this case it's UTF-16, counted the number of bytes and divided by two, and repeated that many times starting at position 2 and incrementing by 1 and deleted every other byte. Now I have pretty looking ASCII text! Bear in mind these values might need to be adjusted slightly depending on your exact flavor of Unicode and this will only work if the characters are essentially ASCIII characters and not the extended Unicode characters. Happy day! Quote Link to comment Share on other sites More sharing options...
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.