Back

If your email is not recognized and you believe it should be, please contact us.

  • You must be logged in to reply to this topic.Login

NEED HELP: Adding Suffix To Character String

Return to Member Forum

  • Author
    Posts
    • #113300

      I’ve got hundreds of text boxes applied to a character style. I need help adding a text suffix to each one of these boxes?

      i.e ‘1B18244’ would be ‘1B18244-X’

      Got anything?

      AB

    • #113438
      Peter Kahrel
      Participant

      > I’ve got hundreds of text boxes applied to a character style

      Not sure what you mean here. How does one apply a text box to a character style? Can you explain what you’re after?

      P.

    • #113442

      Sorry for the confusion. Let me re-word.

      I’ve got hundreds of text boxes and need a suffix added on to the end of each character string.

      For example one text box contains ‘1B18244’ and would need changed to ‘1B18244-X’ (without quotes). I need that same thing to happen hundreds of times across a document.

      Anything that helps?

      AB

    • #113450
      Kal Starkis
      Member

      Hi Alex. Assuming the code (1B18244 in your example) follows a set pattern, you can use a simple GREP pattern to find it and add the suffix. It would look something like this:

      Find what:
      \d[A-Z]\d{5}

      Change to:
      $0-X

      This finds a single digit (\d), followed by any capital letter ([A-Z]), followed by exactly 5 digits (\d{5}). It then takes the found string ($0) and adds the suffix (-X).

      Possible alternative method… In your original question, you mentioned a character style. If every string you’re searching for has the same character style applied, I’d have thought you could also use this to find the string. This seems to work for your example (which has only 7 characters), but when I tried this with longer strings I got unpredictable results. The found string ($0) only grabbed the first part of each string, and the rest got chopped off. I have no idea why it works this way. Perhaps a bug? Or maybe someone else understands what’s going on here.

    • #113459
      Peter Kahrel
      Participant

      A simple script:

      frames = app.documents[0].textFrames.everyItem().getElements();
      for (i = 0; i < frames.length; i++) {
      frames[i].contents += ‘-X’;
      }

      If there’s any formatting in the frames you need the slower version:

      frames = app.documents[0].textFrames.everyItem().getElements();
      for (i = 0; i < frames.length; i++) {
      frames[i].insertionPoints[-1].contents = ‘-X’;
      }

      P.

    • #113460
      Peter Kahrel
      Participant

      Saw Kal’s post only a minute ago. Now why didn’t I think of GREP :)? But it can be done simpler:

      Find what: (.)\Z
      Replace with: $1-X

      (.)\Z matches any character at the end of a story and replaces it it with itself and -X

      P.

    • #113462
      Kal Starkis
      Member

      Ah, I guess we made different assumptions Peter. I thought there might be other text frames that Alex didn’t want the suffix appended to.

      Well Alex, between our suggestions you should be able to find something that fits the bill. :-)

    • #113487
      Masood Ahmad
      Participant

      Peter, you’re great. It seems that scripts pop out on their own From your fingers. Love you!

    • #113537
      Masood Ahmad
      Participant

      Just a refined version of what Kal suggested.

      Try this:

      GREP Find what:
      \d\u\d{5}(?!(-X))

      Change to:
      $0-X

      The above GREP query won’t look for the strings that already have the -X suffix. So you can do a ‘Change All’, blindly.

      Please let us know your thoughts.

Viewing 8 reply threads
  • You must be logged in to reply to this topic.
Forum Ads