[CS5.5] [JS] delete the character before the result of the search

Hello

I have a small question.

I would like to remove all spaces before any text containing the tag with a specific character style.

Example: "call: [SPACE] [BEGIN TANK STYLE FRUIT] 5 parts [END TANK STYLE FRUIT]".

I would like to remove the space...

A piece of my code:

app.findTextPreferences = NothingEnum.nothing;

app.findTextPreferences.appliedCharacterStyle = "FRUIT".

myResultsList = app.activeDocument.findText ();

for (var k = myResultsList.length - 1; k >-1; k = k - 1) {}

How can I remove the space before the result?

}

Aynone have an idea?

Thank you

John

Hi J & J,

I have a little problem with the two scripts here.

Jarek is obviously going to be very fast, but it assumes there is no local formatting on the words of style FRUIT, i.e. No bold / italic / color / highlight replacements applied to these texts. If this is the case then his script (perhaps with a more original original combination) them IS way to go. If it's not!

John, I don't understand how the script you found could possibly work.

There are 2 major bugs with it.

var myCharacters = myResultsList [k] .parentTextFrames [0] .characters;

myCharacters.itemByRange(myLocation-1,1).remove ();

should be replaced by

var myCharacters is myResultsList [k].parentStory.characters;.

myCharacters.itemByRange (myLocation-1, myLocation) .remove ();

To the help of parentTextFrames is not a good idea because it will fail on threaded textframe, give it index the character of possiosion since the beginning of the story and not the beginning of the textframe.

having itemByRange(myLocation-1,1).remove () will withdraw find it until the second character in the story. I understand that you just want to remove the space before the style!

This brings to a 3rd problem in your script that removes the (fixed once upwards) any character preceding the style regardless of whether or not it is a space.

In any case my way would be with one of these 2 functions according to the conditions weather there is always a space before the style of fruits or not.

It will only remove spaces (no returns or other characters) that precede the style.

The first function 'removeCharacterBeforeStyle' is the equivalent of your corrected script but better (at least in my humble opinion)

// http://forums.adobe.com/thread/1213463?tstart=0word.
// Removes  letter / spaces before a character style
app.doScript("removeAllSpacesBeforeStyle()", ScriptLanguage.javascript, undefined, UndoModes.ENTIRE_SCRIPT);
//app.doScript("removeCharacterBeforeStyle()", ScriptLanguage.javascript, undefined, UndoModes.ENTIRE_SCRIPT);

function removeCharacterBeforeStyle() {
    // to delete ANY character that precedes the FRUIT style. short and sweet :-)
    app.findTextPreferences = null;
    app.findTextPreferences.appliedCharacterStyle = "FRUIT";
    var  myFinds =  app.documents[0].findText(),
           l = myFinds.length, pos;
    while (l--)   myFinds[l].parentStory.characters.itemByRange (pos = myFinds[l].insertionPoints[0].index-1, pos++).remove();
};

function removeAllSpacesBeforeStyle() {
    // This will delete spaces (including hairspaces), tabs etc. but not returns that precedes the FRUIT style
    // see http://www.indiscripts.com/post/2011/09/what-exactly-is-a-word for hairspace and other potential issues
    // not so short and not so sweet :-(
    // but does the job without messing up most of the local overrides of the character style |:-)
    var doc = app.documents[0];
    app.findTextPreferences = app.changeTextPreferences = null;
    app.findTextPreferences.findWhat = "^|"; // this is one way of dealing with hairline spaces (warning their format will get messed up)
    app.changeTextPreferences.changeTo = "^4^4^4^4^3";
    doc.changeText();
    app.findTextPreferences = null;
    app.findTextPreferences.appliedCharacterStyle = "FRUIT";
    var  myFinds = doc.findText(),
           l = myFinds.length,
           ps, find_CharacterInStoryIndex, find_WordInStoryIndex, StartOfGap, EndOfGap;
    app.findTextPreferences = app.findGrepPreferences = app.changeGrepPreferences = null;
    app.findGrepPreferences.findWhat = "((?![\\r\\n])\\s)+"; // find spaces that are not returns about the same as "[~m~>~f~S~s~<~/~.~3~4~%\\x{20}~|\\t]+" I have not compaired the speeds
    while (l--)  {
        ps = myFinds[l].parentStory;
        find_CharacterInStoryIndex = myFinds[l].insertionPoints[0].index-1;
        if ((find_WordInStoryIndex = ps.words.itemByRange(ps.words[0], myFinds[l].words[0]).words.length-2) <0) continue;
        // the 'if' checks that the find is not the first word in the story if it was the ALL the spaces in the whole story would be removed
        StartOfGap = ps.words[find_WordInStoryIndex].insertionPoints[-1].index;
        EndOfGap = ps.words[find_WordInStoryIndex+1].index-1;
        // if the FRUIT style starts at the beginning  of a word remove spaces before that word
        if (find_CharacterInStoryIndex == EndOfGap)  ps.characters.itemByRange(StartOfGap,EndOfGap).changeGrep();
    }
    app.findTextPreferences.findWhat = "^4^4^4^4^3"; // put the hairspaces back
    app.changeTextPreferences.changeTo = "^|";
    doc.changeText();
    app.findTextPreferences  = app.changeTextPreferences = app.findGrepPreferences = null;
}

Concerning

Trevor

P.s. If you do not have hairspaces (and you probably haven't) her you could for aesthetic reasons to remove at least 6 lines of code.

Tags: InDesign

Similar Questions

  • Photoshop closed unexpectedly cs5.1 and delete the file I was working on that

    Photoshop closed unexpectedly cs5.1 and delete the file I was working on that

    Hi jasonb80685354,

    Greetings.

    • Unfortunately, there is nothing that can be done apart from with a record back if you a.

    Concerning

    Rohit

  • Cannot delete the search engines on my Mac. "Delete" button is grayed out. ??

    I tried to search for reset addon and nothing has changed.

    It also seems that Firefox change my settings as homepage and the size of the police.

    I'm not very tech savvy.

    Mac Mini running Yosemite 10.10.2

    Thank you

    See it works on MacOSX.

    Put this in the address bar and press ENTER.

    chrome://browser/content/search/engineManager.XUL

    You can copy and paste this address in "internal".

    Select the search engine you want to delete, and then use the Remove button in the bottom right.

  • How to delete the search history?

    Don't like banking info showing

    Depends on where it appears. Long pressing the article can provide a delete option. If this does not work then please provide clear steps to what your problem is. Screenshots would be useful.

  • Delete the search bar

    I can type my search in the address bar. Why do I need a separate search beside him bar? How can I get rid of him? And I can't find the RSS FEED button more. And yet one thing - your "Help button" should be replaced by a box 'he is NO help... "

    "Now you know a way to control the length of the URL address box. Does not seem a thingie adjust at the end."

    This control is rendered inoperative when the address bar and search bar are no longer in their original position. You can use code userChrome.css to fix the length or the address bar.

     #urlbar {
    max-width: 600px !important;
    }
     

    Use whatever number you want for the size of the window of the address bar.

    If you do not know the 3 'user' files can be used in Firefox, it is easier to use this extension to add this code in the userChrome.css file.

  • delete the search yahoo on chrome engine

    Recently (although this seems to be an older problem for Windows users), my default search engine has been hijacked to display Yahoo whenever I click on 'new tab' on Chrome. It's happened on Safari, but solved the problem by changing the default settings.

    The solutions I could find are all specific to Windows. Does anyone have a Mac solution?

    Running Chrome v47... (to date) on a 2-year-old iMac, v10.10.5, using Avast security. Interestingly, the Avast icon is gray when the Yahoo Search tab is turned.

    Use Malwarebytes Anti-Malware: http://www.adwaremedic.com/index.php

    Reset Google Chrome settings: reset of the browsers on OS X (Safari, Chrome, Firefox)

  • How can I delete the search history and cookies?

    I don't know where to go for delete my search history & cookies...

    U should go on your browser settings-> privacy-> clear now and u can select what you want to remove, once this press 'clear data'! I hope that this will help u. PS. Sorry if my English is bad, but I'm from other country!

  • How can I delete the history of the card in the iPad 2?

    I'm trying to delete search history in the Maps application.  All previous searches appear when I start typing a new map search.  I know how to delete the search history in Safari, but it doesn't work for the map application.  Any help would be appreciated.

    Open maps app,

    Press search

    Tap Favorites

    recent valve (bottom)

    clear tap (upper-left)

  • If I delete a file in the search results pane, am I actually delete the file or just the result of search?

    I'm a bit confused about the Windows XP search results pane.  I need to winnow down remove some of the documentation noted that the results do not apply.  If I remove them in the search results pane, am I actually remove the document from the PC or just delete the search result and leave the document in its original file?

    Hello

    You delete the file. Try it yourself...

    • For example, create a document with a unique name (say qwerty987.doc) word
    • Search all files and folders to qwerty987
    • Right-click on the file in the search results, and then click Open containing folder
    • Research of two results of window and the window of the folder containing the visible file (resizing and movement to achieve, as appropriate)
    • Remove the test file in the search results window and watch it disappear from the other window too

    Tricky

  • The search bar has no motor; then when I 'manage', basics like google are not available (probably because it should be there by default). Help!

    I tested each beta without any real problems. Then, when I installed 4b 11, I tried to use the search bar, and it wouldn't work. I clicked on the menu drop down and realized that all the engines had disappeared. So, I went to "manage search engines" and confirmed that none have been installed. The problem is, when I click on "get more search engines," I can only find variations on the engines real I want..., google, yahoo, etc. I'm guessing that because it should be there as part of the software? I have now 4.0RC, and the same problem exists. Please help, you have my gratitude!

    1. Click the icon to search on the search bar engine
    2. Open "manage search engines".
    3. Click on "Restore default settings"

    You can also try to delete the search.sqlite and search.json files in the Firefox profile folder

  • I've just updated to firefox 9.0.1 and when I go to my emails on email yahoo, the bar that allows me to delete, answer, etc. before is inactive and I can't answer or delete my mails. can you please give me help!

    I can't manage my emails as deleting as toolbar with delete, answer, guests etc. before is not active and does not respond when I click on the guests like trying to delete the emails

    Included in the list Extensions with your original question (click on "Details system more to the right of your original question):

    AVG Security Toolbar 9.0.0.18.1 true avg@toolbar

    Real [email protected] Babylon 1.1.3

    Java Quick Starter 1.0 true [email protected]

    Yahoo! Toolbar 2.4.5.20111209014555 true {635abd67-4fe9-1b23-4f01-e679fa7484c1}

    Fake AVG Safe Search 10.0.0.1410 {1E73965B-8B48-48be-9C8D-68B920ABC1C4}

    list continues...

    You will probably need to use the information contained in http://kb.mozillazine.org/Uninstalling_toolbars (shown above) to remove the program from your system via the Windows Control Panel.

    If this answer solved your problem, please click 'Solved It' next to this response when connected to the forum.

  • Changes in Word, when I enter a character or letter, it deletes the next character

    original title: change in Word

    I was to edit a multiple page document.  So far, if I add or change a character, he just replaced what I typed.  All of a sudden, when I enter a character or letter, it deletes the next character.  I lose words or letters.  How to get back to editing without erasing it?

    Press ENTER on your keyboard.  See http://en.wikipedia.org/wiki/Insert_keyif you happen to have Word 2007 (or 2010) see http://help.lockergnome.com/office/Insert-key-work--ftopict1003194.html or http://www.technize.com/how-to-enable-insert-key-in-microsoft-word-2007-word-2010/

  • My InDesign Cs5 is currently blocked, while I deleted the file plugins SING. Please, someone help me.

    My InDesign CS5 is suspended, every time I start up my InDesign, I deleted the file plugins, but still his hanging, pls SING, somebody help me. My Photoshop Cs5, Illustrator Cs5 works correctly, but InDesign doesn't work do not.

    Hey, Peter I solved my problem of Bro in some fonts do not support my indesign. So, I took off bad fonts and now its all working properly.

    Thank you Peter for your help.

  • I've just updated Adobe Professional, but I'm not able to add, to delete the pages more. Before the update, it wasn't a problem. I missed something?

    I've just updated Adobe Professional, but I'm not able to add, to delete the pages more. Before the update, it wasn't a problem. I missed something?

    Are you sure that you're not open your files with the free player instead of using Acrobat? And please do not post the same question multiple times. Also, try to be more specific. "I am not able" can mean many different things.

  • Add the tab character before the content of particular paragraph style

    I have to add the tab character before the content of particular paragraph style

    app.findTextPreferences.appliedParagraphStyle = app.activeDocument.paragraphStyles.item ("IDX2");

    list = app.activeDocument.findText ();

    // 2. For each found the point...

    for (i = 0; i < list.length; i ++)

    {

    App.Select (list [i])

    App.Selection[0].insertionPoints[0].contents="\t".

    }

    But the code above only works in the first instance. But I must add the tab character all the content of the paragraph applied

    How to do this

    Hello

    Another way without GREP...

    var doc = app.activeDocument;
    var myStories=doc.stories;
    var J= myStories.length;
    
    while( J-- ){
        var mStorie = myStories[J];
        var K= mStorie.paragraphs.length
        while( K-- ){
            if  (mStorie.paragraphs[K].appliedParagraphStyle.name == "toto") {
                mStorie.paragraphs[K].contents= "\t" + mStorie.paragraphs[K].contents;
            }
         }
    }
    

Maybe you are looking for

  • When I check my battery icon it says, ' Condition: replace soon "why?

    Recently my 2010 Macbook Pro battery icon when you press says "Condition: replace soon" why?

  • problem to activate Vista after a Toshiba system restore

    I did a full restore using a new restore disc, I bought at Toshiba. I restored the computer but had to do a restore again. Now I can not turn on. I don't have activation key. Can help?

  • Line of laptop Dell Inspiron 15R in number

    Hello Forum, I have a Dell Inspiron 15R laptop touch Windows 8. I wanted to listen to my iPod Nano on the laptop and connected via the line to the port with a cable to THE. The sound comes through and I hear it on the speakers of systems, but there i

  • How to prevent the launcher application

    Hello I want to block any application to launch. Suppose I'm clicking on a native application such as Blackberry Messenger. So I want to prevent that application to run through my code. What API should I use and how? Thanks in advance

  • Can't get AVG off of my computer... Windows 7

    I tried to uninstall AVG from my computer I want to reinstall it later.  I uninstalled it... but it still shows up on top of the list of software to uninstall. It doesn't seem to work as when I go to start and type in the average. nothing comes.  I t