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

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

Advisor ,
Jul 04, 2012 Jul 04, 2012

Copy link to clipboard

Copied

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

Views

801

Translate

Translate

Report

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 ~

Votes

Translate

Translate
Guru ,
Jul 04, 2012 Jul 04, 2012

Copy link to clipboard

Copied

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 ~

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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();

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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()

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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