Skip to main content
dublove
Legend
Aug 21, 2026 9:17 AM UTC
Answered

How to obtain the longest character with ":" and the offset value of the first character after ":"?

I have chosen some regular text, and I want to get the horizontalOffset of the first character after the longest character ':'.

The horizontal offset of the word I circled in the picture.
May I ask how to write the code? 

Thank you very much.

 

    Peter Kahrel
    Peter KahrelCorrect answer
    Community Expert
    Aug 21, 2026 1:14 PM UTC

    Select the text frame with the colons (or select a few lines), then…

    app.findGrepPreferences = null;
    app.findGrepPreferences.findWhat = ': \\K';
    x = app.selection[0].findGrep();

    max = 0;
    for (i = 0; i < x.length; i++) {
    max = Math.max (x[i].horizontalOffset);
    }

    alert (max);

     

    4 replies

    Peter Kahrel
    Community Expert
    Peter KahrelCommunity ExpertCorrect answer
    Community Expert
    Aug 21, 2026 1:14 PM UTC

    Select the text frame with the colons (or select a few lines), then…

    app.findGrepPreferences = null;
    app.findGrepPreferences.findWhat = ': \\K';
    x = app.selection[0].findGrep();

    max = 0;
    for (i = 0; i < x.length; i++) {
    max = Math.max (x[i].horizontalOffset);
    }

    alert (max);

     

    Translate
    dublove
    dubloveAuthor
    Legend
    Aug 21, 2026 2:49 PM UTC

    Hi ​@Peter Kahrel 

    I tested it
    alert(x[i].horizontalOffset);
    It seems that none of the three values are correct.

    Translate
    Peter Kahrel
    Community Expert
    Community Expert
    Aug 21, 2026 4:04 PM UTC

    Well, you wanted the biggest value, so there's only one correct value.

    In what way is it not correct?

    Translate