Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7506861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:22:13+00:00 2026-05-29T22:22:13+00:00

I have a file that contains Unicode text in an unstated encoding. I want

  • 0

I have a file that contains Unicode text in an unstated encoding. I want to scan through this file looking for any Arabic code points in the range U+0600 through U+06FF, and map each applicable Unicode code point to a byte of ASCII, so that the newly produced file will be composed of purely ASCII characters, with all code points under 128.

How do I go about doing this? I tried to read them the same way as you read ASCII, but my terminal shows ?? because it’s a multi-byte character.

NOTE: the file is made up of a subset of the Unicode character set, and the subset size is smaller than the size of ASCII characters. Therefore I am able to do a 1:1 mapping from this particular Unicode subset to ASCII.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T22:22:14+00:00Added an answer on May 29, 2026 at 10:22 pm

    This is either impossible, or it’s trivial. Here are the trivial approaches:

    • If no code point exceeds 127, then simply write it out in ASCII. Done.

    • If some code points exceed 127, then you must choose how to represent them in ASCII. A common strategy is to use XML syntax, as in α for U+03B1. This will take up to 8 ASCII characters for each trans-ASCII Unicode code point transcribed.

    The impossible ones I leave as an excercise for the original poster. I won’t even mention the foolish-but-possible (read: stupid) approaches, as these are legion. Data destruction is a capital crime in data processing, and should be treated as such.

    Note that I am assuming by ‘Unicode character’ you actually mean ‘Unicode code point’; that is, a programmer-visible character. For user-visible characters, you need ‘Unicode grapheme (cluster)’ instead.

    Also, unless you normalize your text first, you’ll hate the world. I suggest NFD.


    EDIT

    After further clarification by the original poster, it seems that what he wants to do is very easily accomplished using existing tools without writing a new program. For example, this converts a certain set of Arabic characters from a UTF-8 input file into an ASCII output file:

    $ perl -CSAD -Mutf8 -pe 'tr[ابتثجحخد][abttjhhd]' < input.utf8 > output.ascii
    

    That only handles these code points:

    U+0627 ‭ ا  ARABIC LETTER ALEF
    U+0628 ‭ ب  ARABIC LETTER BEH
    U+0629 ‭ ة  ARABIC LETTER TEH MARBUTA
    U+062A ‭ ت  ARABIC LETTER TEH
    U+062B ‭ ث  ARABIC LETTER THEH
    U+062C ‭ ج  ARABIC LETTER JEEM
    U+062D ‭ ح  ARABIC LETTER HAH
    U+062E ‭ خ  ARABIC LETTER KHAH
    U+062F ‭ د  ARABIC LETTER DAL
    

    So you’ll have to extend it to whatever mapping you want.

    If you want it in a script instead of a command-line tool, it’s also easy, plus then you can talk about the characters by name by setting up a mapping, such as:

     "\N{ARABIC LETTER ALEF}"   =>  "a",
     "\N{ARABIC LETTER BEH}"    =>  "b",
     "\N{ARABIC LETTER TEH}"    =>  "t",
     "\N{ARABIC LETTER THEH}"   =>  "t",
     "\N{ARABIC LETTER JEEM}"   =>  "j",
     "\N{ARABIC LETTER HAH}"    =>  "h",
     "\N{ARABIC LETTER KHAH}"   =>  "h",
     "\N{ARABIC LETTER DAL}"    =>  "d",
    

    If this is supposed to be a component in a larger C++ program, then perhaps you will want to implement this in C++, possibly but not necessary using the ICU4C library, which includes transliteration support.

    But if all you need is a simple conversion, I don’t understand why you would write a dedicated C++ program. Seems like way too much work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a file that contains this kind of paths: C:\bad\foo.c C:\good\foo.c C:\good\bar\foo.c C:\good\bar\[variable
I have Text file that contains data separated with a comma , . How
I have a text file that contains a long list of entries (one on
I have a text file that contains about 100000 articles. The structure of file
C++ is not my preferred language. I have a file that contains this: e
I have a file that contains a mish-mash of cities, states, and zip codes.
I have a file that contains: foo1 = 1 foo2 = 2 foo3 =
I have a file that contains the following in a csv file; country,region,city,postalCode,metroCode,areaCode I
Suppose you have a file that contains IP addresses, one address in each line:
I have a file that I set using PowerShell that contains the version number

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.