Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help capturng unicoded directory names
#26
(12-18-2024, 11:34 PM)SMcNeill Wrote: If I have to sort out what type of encoding you used for a mystery text file, I simply don't need to read that mystery file.   If it's not ASCII page 437 (which is pretty much the default), or UTF-8, then you need to tell me what format it's in, or else I simply won't worry over it at all.  IF it's something that seems like it might *kill* me not to know its contents, then I might try *once* to load it in Word or Office and see if it can detect the information.  If not, then I'll just die.

Nobody has time to be running around and guessing at encoding types.  If the other guy can't *tell* you what the encoding is and what then endianness is, then he doesn't have anything worth saying anyway.  It's just not worth the hassle.

Seems a bit of a foolish take. A 5 second search on Google provides this:

Code: (Select All)
#include <fstream>
#include <iostream>

int main() {
    std::ifstream file("your_file.txt", std::ios::binary);
    if (!file.is_open()) {
        std::cerr << "Error opening file!" << std::endl;
        return 1;
    }

    char bom[3];
    file.read(bom, 3);

    if (bom[0] == 0xEF && bom[1] == 0xBB && bom[2] == 0xBF) {
        std::cout << "Encoding: UTF-8" << std::endl;
    } else if (bom[0] == 0xFF && bom[1] == 0xFE) {
        std::cout << "Encoding: UTF-16 Little Endian" << std::endl;
    } else if (bom[0] == 0xFE && bom[1] == 0xFF) {
        std::cout << "Encoding: UTF-16 Big Endian" << std::endl;
    } else {
        std::cout << "Encoding: Unknown" << std::endl;
    }

    return 0;
}

A 15 second search on Google reveals this:
AutoItConsulting/text-encoding-detect: C# and C++ UTF8/UFT16 encoding detection library.
Tread on those who tread on you

Reply


Messages In This Thread
RE: Need help capturng unicoded directory names - by SpriggsySpriggs - Yesterday, 12:33 PM



Users browsing this thread: 2 Guest(s)