In other words, something analagous to
"The black cat walks in the hall".substring(2,11)
but for Indesign text objects, instead of strings.
I'm sure there's something really simple I'm just not thinking of.
To grab a range of characters, use itemByRange on the story's Characters property:
story = app.activeDocument.stories; range = story.characters.itemByRange(2,11); alert ("Story: "+story.contents+"\nRange: "+range.contents+"\nType: "+range.constructor.name+"\nLength: "+range.length);
Thank you Jongware, that's great!
I didn't try that because I assumed that collections of characters wouldn't be counted as blocks of text for the purposes of things like searching, but I was wrong. I added this to your example:
(Starting with story.contents == "The black cat walks down the hall.")
var story = app.activeDocument.stories; var range = story.characters.itemByRange(2,11); app.findTextPreferences = NothingEnum.nothing; app.changeTextPreferences = NothingEnum.nothing; app.findTextPreferences.findWhat = "black"; app.changeTextPreferences.changeTo = "white"; range.changeText();
and it totally worked. Turned into "The white cat walks down the hall."