We have a project where we need to convert weird characters generated from all kinds of file formats into ASCII due to compatibility issues. Is it possible in Sublime Text 2 to convert the encoding of a document to ASCII? We can't convert it to any extended/non-ASCII character set if it includes more characters that are not supported.

  • 4
    7-bit ASCII has no support for "weird characters". So you want to just remove them from the file? If so, open with any 8 bit encoding and search for regular expression [\x80-\xff], replacing it with nothing. – Daniel Beck Jan 16 '13 at 15:32
  • 2
    ANSI is the organization that made ASCII so your question makes no sense. – barlop Dec 7 '14 at 22:50
  • @barlop - Windows incorrectly refers to non-Unicode character sets as "ANSI" code pages, so that may be the source of the confusion. – dave Nov 4 '18 at 23:06
  • The OP specifically says he wants to "convert weird characters ... into ASCII". What does this in fact mean? Ignore them? Replace with ASCII SUB (0x1A)? Insert some "equivalent" sequence? – dave Nov 5 '18 at 2:19
  • @dave well I think it often means he wants all chars to be within 0-127 For example, if you paste some stuff from online into notepad and try to save, the default is what notepad calls "ANSI" and anything > 127 , when saving with ansi(which is default), will cause a prompt to say "the file contains characters in a format that will be lost". If saved the file may end up with lots of question mark characters in there in place of the >127 character. – barlop Nov 5 '18 at 16:45

Sublime text 2 will allow you to save with a variety of encodings, but won't do so if you have characters that don't fit in the encoding you are saving to. I had a problem recently were I was getting encoding errors at various positions in Mako templates and since the characters were not displayable in sublime text I couldn't even see them to remove them. So I opened the file in the hex editor HxD changed the offset base to decimal and went straight to the positions specified in the errors and removed the offending characters; Problem solved.

Also it didn't help me in this case but you might find this useful. https://stackoverflow.com/questions/12943594/is-it-possible-to-show-the-exact-position-in-sublime-text-2 The link above includes source that if saved to Preferences > Browse Packages > User will add absolute position of the cursor to the status line at the bottom of the Sublime Text window, though this didn't help me since the offending characters weren't displayable.

  • You wrote "changed the offset base to decimal" What. Why don't you state what hex editor that was. It's not clear what changing the offset base to decimal means until reading where you later write "the positions specified in the errors" But then it's not that clear what you mean a'cos you haven't shown the errors you mean. I get the jist of what you're saying but you are writing very unclearly, stating things later that should be said earlier, and not giving examples. – barlop Nov 6 '18 at 9:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.