Skip to main content
Bedazzled532
Inspiring
Jan 11, 2025 5:40 PM UTC
Answered

Unicode Number conversion

Hi,

I have a list of sentences with numbers at the start. Generally unicode values of numbers should be from 30-39, however, since the matter is in arabic and I need the numerls in 30 - 39 unicode values, I need to convert it from arabic system to english system.

 

i.e \x{6f0} to \x{30} for number 0

\x{6f1} to \x{31} for number 1 .... and so on.

 

As there are more than 10000 numbers it will take forever. How can I do this in InDesign ?

Thanks

Peter Kahrel
Peter KahrelCorrect answer
Community Expert
Jan 12, 2025 9:11 AM UTC

If you want to target all numbers, simply remove the ^ in the second line. But if you want to convert only paragraph-initial numbers you need the following:

app.findGrepPreferences = null;
app.findGrepPreferences.findWhat = '^[\\x{06F0}-\\x{06F9}]+';
d = app.documents[0].findGrep();
for (i = d.length-1; i >= 0; i--) {
  s = d[i].contents;
  for (j = s.length-1; j >= 0; j--) {
    d[i].characters[j].contents = String (s.charCodeAt(j) - 1776);
  }
}

 

16 replies

Peter Kahrel
Community Expert
Community Expert
Jan 11, 2025 9:21 PM UTC

The 10-times-find-and-replace works fine, of course, but it's not too difficult to convert found Arabic-Indic digits to, uhm, Arabic:

app.findGrepPreferences = null;
app.findGrepPreferences.findWhat = '^[\\x{06F0}-\\x{06F9}]';
d = app.documents[0].findGrep();
for (i = d.length-1; i >= 0; i--) {
  d[i].contents = String (d[i].contents.charCodeAt() - 1776);
}

You find an Arabic-Indic digit and replace it with its decimal value minus 1776. (The decimal value of the Arabic-Indic 0 is 1776.)

Translate
Bedazzled532
Inspiring
Jan 12, 2025 6:16 AM UTC

@Peter Kahrel Thanks for this wonderful code, however, the code works on single digits only. For two or more digits, it is not working. It just takes one digit from 2 or 3 digits number and converts and leaves the rest.

 

Translate
Peter Kahrel
Community Expert
Peter KahrelCommunity ExpertCorrect answer
Community Expert
Jan 12, 2025 9:11 AM UTC

If you want to target all numbers, simply remove the ^ in the second line. But if you want to convert only paragraph-initial numbers you need the following:

app.findGrepPreferences = null;
app.findGrepPreferences.findWhat = '^[\\x{06F0}-\\x{06F9}]+';
d = app.documents[0].findGrep();
for (i = d.length-1; i >= 0; i--) {
  s = d[i].contents;
  for (j = s.length-1; j >= 0; j--) {
    d[i].characters[j].contents = String (s.charCodeAt(j) - 1776);
  }
}

 

Translate
Community Expert
Jan 11, 2025 6:02 PM UTC

You might be able to do it with a script - but I don't have ME version of InDesign installed to test - perhaps if you share a sample file or selection of text or something.

I could download the ME version and test it with a custom script if you like. 

 

Should be doable. 

 

You might not need a custom script

There's a find change script already with InDesign that allows you to add GREP search find and replace 

It might work.

Translate
Robert at ID-Tasker
Legend
Jan 11, 2025 6:04 PM UTC

@Eugene Tyson

 

You don't need ME version.

 

@Bedazzled532 

 

F&C run 10x times - for every digit - should work.

 

Or do you need to re-calculate values? 

 

Translate
Community Expert
Jan 11, 2025 6:26 PM UTC

 

quote

@Eugene Tyson

 

You don't need ME version.

 

@Bedazzled532 

 

F&C run 10x times - for every digit - should work.

 

Or do you need to re-calculate values? 

 


By @Robert at ID-Tasker

 

Yeh i was thinking that on both of those things

But hey - rather work in the same version the OP is to make sure it's ok.

 

And I was thinking find change for 10 things too 0-9 should do it.

Translate
Robert at ID-Tasker
Legend
Jan 11, 2025 6:02 PM UTC

A simple script can do this - but would be easier if you post an example screenshot.

 

Translate
Bedazzled532
Inspiring
Jan 11, 2025 6:10 PM UTC

@Robert at ID-Tasker  and @Eugene Tyson I am attaching sample file.

Translate