Skip to main content
Bedazzled532
Inspiring
January 11, 2025
Answered

Unicode Number conversion

  • January 11, 2025
  • 3 replies
  • 1620 views

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

Correct answer Peter Kahrel

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);
  }
}

 

3 replies

Peter Kahrel
Community Expert
Community Expert
January 11, 2025

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.)

Bedazzled532
Inspiring
January 12, 2025

@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.

 

Peter Kahrel
Community Expert
Peter KahrelCommunity ExpertCorrect answer
Community Expert
January 12, 2025

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);
  }
}

 

Community Expert
January 11, 2025

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.

Robert at ID-Tasker
Legend
January 11, 2025

@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? 

 

Community Expert
January 11, 2025

 

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.

Robert at ID-Tasker
Legend
January 11, 2025

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

 

Bedazzled532
Inspiring
January 11, 2025

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