Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Help! Getting the index of a Character from the Characters collection

Advisor ,
Jul 04, 2012 Jul 04, 2012

so, in a script i need to remove the text from the begining of the paragraph until the first tab (or dot or colon or "something") charater as simple and as fast as posible.

i was hoping for something like

myText=myParagraph.characters.itemByRange(0,"\t");

myText.remove();

Ofcourse i can use grep, but it has it's problems, and i was hoping i don't have to (especialy since the script will have to do this for 400+ times.

Any help?

TOPICS
Scripting
938
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guru , Jul 04, 2012 Jul 04, 2012

Vamitul

I don't know if that's the way do go about it but this is what you are looking for.

myParagraph=app.selection[0].paragraphs[0];

myText=myParagraph.characters.itemByRange(0,myParagraph.contents.toString().indexOf("\t"));

myText.remove();

To delete until the tab not including it use myText=myParagraph.characters.itemByRange(0,myParagraph.contents.toString().indexOf("\t")-1);

Trevor

Message was edited by: ~ Trevor ~

Translate
Guru ,
Jul 04, 2012 Jul 04, 2012

Vamitul

I don't know if that's the way do go about it but this is what you are looking for.

myParagraph=app.selection[0].paragraphs[0];

myText=myParagraph.characters.itemByRange(0,myParagraph.contents.toString().indexOf("\t"));

myText.remove();

To delete until the tab not including it use myText=myParagraph.characters.itemByRange(0,myParagraph.contents.toString().indexOf("\t")-1);

Trevor

Message was edited by: ~ Trevor ~

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Jul 04, 2012 Jul 04, 2012

Thank you.

that's how i did it, but i think it's kind of a very ugly hack.

Also text.contents already returns a string, so no need for .toString();

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Jul 04, 2012 Jul 04, 2012

Pleasure

The .toString() is a bit safer.

Try the script with the first line

myParagraph=app.selection[0].paragraphs.everyItem();

It works with the toString and doesn't without.

So it depends on how you define myParagraph

But as you wrote myParagraph and not myParagraphs you probably don't need the toString()

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Jul 04, 2012 Jul 04, 2012
LATEST

.everyItem() returns a array of paragraphs, so ofcourse it doesn't work. Anyway the paragraph part was a simplification. The actual code i needed was:

fNote.characters.itemByRange(0,fNote.contents.indexOf(separator)-1).contents=doc.footnoteOptions.prefix+String(j+1)+doc.footnoteOptions.suffix;

I had to make a script to change/restart the footnote numbering on a "per frame" basis.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines