Skip to main content
csm_phil
Legend
October 30, 2010
Question

How to check the words of next characters is Capital Leter or not its Urgent!

  • October 30, 2010
  • 2 replies
  • 525 views

Hi Developers,


I have one question and help.

This is my input text

W.1.7 Participate in shared research

Sesearch to Build and Present Knowledge

W.1.6 with guidance and support

Change to this:

W.1.6-with guidance and support

I mean W.1.6(enspace insert)with guidance and support. And check next word of characters is CAPS then insert enspace otherwise leave as it is.


this is mycode:


var mySel = app.selection[0];
myFirst = mySel.words[0];
//alert(mySel.words[1].characters[0].capitalization == Capitalization.ALL_CAPS);

if(mySel.words[1].characters[0].changecase == ChangecaseMode.UPPERCASE){
    mySel.words[1].insertionPoints[0].contents= SpecialCharacters.EN_SPACE;
    }


regards

CSM_PHIL

This topic has been closed for replies.

2 replies

Jongware
Community Expert
Community Expert
October 30, 2010

if(mySel.words[1].characters[0].changecase == ChangecaseMode.UPPERCASE)

This piece of code does not make ANY sense at all. You cannot use 'changecase' here -- it's a function, not a property. Similar, you cannot 'compare' to ChangecaseMode.UPPERCASE -- that's no a value 'assigned' to some text.

You could check if the next character's toUpperCase is the same as what's already there:

if(mySel.words[1].characters[0].contents.toUpperCase() == mySel.words[1].characters[0].contents)

  ...

Note I'm referring to contents, because the toUpperCase function does not work on "InDesign text", but only on plain Javascript strings.

October 30, 2010

It would be simpler to do with a GREP-search, than with scripting.

It would be something like this (I have not tested it)

Find:

(\u\.\d+\.\d+) (\l)

Replace:

$1~>$2