Replacing Text; Inserting Special Characters - Adobe 65009333 - InCopy CS4 - PC Manual

Scripting guide: javascript
Hide thumbs Also See for 65009333 - InCopy CS4 - PC:
Table of Contents

Advertisement

Text and Type

Replacing text

The following script replaces a word with a phrase, by changing the contents of the appropriate object (for
the complete script, see ReplaceWord):
//Enters text in the default story and then replaces
//a word in the story with a different phrase.
var myDocument = app.documents.add();
var myStory = myDocument.stories.item(0);
myStory.contents = "This is some example text.";
//Replace the third word "some" with the phrase
//"a little bit of".
myStory.words.item(2).contents = "a little bit of";
The following script replaces the text in a paragraph (for the complete script, see ReplaceText):
//Enters text in the default story, and then replaces
//the text in the second paragraph.
var myDocument = app.documents.add();
var myStory = myDocument.stories.item(0);
myStory.contents = "Paragraph 1.\rParagraph 2.\rParagraph 3.\r";
//Replace the text in the second paragraph without replacing
//the return character at the end of the paragraph. To do this,
//we'll use the ItemByRange method.
var myStartCharacter = myStory.paragraphs.item(1).characters.item(0);
var myEndCharacter = myStory.paragraphs.item(1).characters.item(-2);
myStory.texts.itemByRange(myStartCharacter, myEndCharacter).contents = "This text
replaces the text in paragraph 2.";
In the script above, we used the
paragraph. We did this because deleting the return might change the paragraph style applied to the
paragraph. We supplied two characters—the starting and ending characters of the paragraph—as
parameters to the

Inserting special characters

Because the ExtendScript Toolkit supports Unicode, you can simply enter Unicode characters in text
strings you send to InCopy. Alternately, you can use the JavaScript method of explicitly entering Unicode
characters by their glyph ID number: \unnnn (where nnnn is the Unicode code for the character). The
following script shows several ways to enter special characters (for the complete script, see
SpecialCharacters):
itemByRange
method.
itemByRange
method to exclude the return character in the second
Entering and importing text 26

Advertisement

Table of Contents
loading

This manual is also suitable for:

Incopy cs4

Table of Contents