Skip navigation
bduffy323
Currently Being Moderated

replacing text that maintains styling issue

Apr 6, 2012 6:17 AM

Tags: #find #text #replace #styling #find/replace

I am trying to replace text in a textframe and have it maintain the styling that is applied to the text that I am replacing. For example I want to replace:

 

<text1>

<text2>

 

with

 

this text is bold

this text is italic

 

The code I am using is just a simple javascript regex to replace the text:

 

var myContents = new String(myPageItem.parentStory.contents);
 
 
var re1 = new RegExp("<copy1>","gi");
myContents = myContents.replace(re1,"this text is bold");
 
 
var re2 = new RegExp("<copy2>","gi");
myContents = myContents.replace(re2,"this text is italic");
 
 
myPageItem.contents = myContents;
 

 

However, after running the code above I get:

 

this text is bold

this text is italic

 

It seems that only seven characters (which coincidently <copy1> also has seven characters) gets the first style, and the rest of the text after the 7 characters gets the second style. ANY help would be greatly appreciated!

 

 

Thanks in advanced.

 
Replies
  • Currently Being Moderated
    Apr 6, 2012 6:52 AM   in reply to bduffy323

    Messing with contents is tricky, because this changes just the characters "inside" the text -- it has no effect on formatting.

     

    See http://forums.adobe.com/thread/791512?tstart=0

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 24, 2012 2:27 PM   in reply to bduffy323

    >Another question for you Jongware.

     

    Just for me? Oh come on, let the others have a bit of fun as well.

     

    I cannot try your code because it contains too many errors (vAliasObj? myAlias? etc.). Please write a minimal piece of code that shows the behaviour you mention.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 26, 2012 9:40 PM   in reply to bduffy323

    Hi,

     

    I have one simple doubt, could clarify it.

     

    q = 0 <= p && (-1 + p + mySearch.length);

     

    How this line worrks, what it means. I hope this is related to biwise operators.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 27, 2012 6:06 AM   in reply to bduffy323

    Hi Jongware,

    I have one simple doubt, could clarify it.

     

    q = 0 <= p && (-1 + p + mySearch.length);

     

    How this line works, what it means. I hope this is related to bitwise operators.

    Could you please explain what it does actually?

     

    Thanks,

    Green4ever

     
    |
    Mark as:
  • John Hawkinson
    5,572 posts
    Jun 25, 2009
    Currently Being Moderated
    Apr 27, 2012 9:47 PM   in reply to Green4ever

    Green4ever wrote:

    Could you please explain what it does actually?

    Please don't post the same thing twice.

    Especially without trying!

    See my answer in http://forums.adobe.com/message/4366682#4366682

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 27, 2012 10:24 PM   in reply to John Hawkinson

    Hi John,

     

    First I posted here, Since it is a answered question i'm not getting the response from anyone.

    Apr 27, 2012 7:06 AM (in response to bduffy323)

    After that only I posted it as a new dicussion.

     

    Apr 27, 2012 10:09 PM

    Please don't post the same thing twice.

    Especially without trying!

    See my answer in http://forums.adobe.com/message/4366682#4366682

    I am already following your answer in the thread you mentioned. Please check the timing if you any doubt.

     

    ---

    Edit:

    I need know how the below line works,See this thread http://forums.adobe.com/message/4364545#4364545

    I already metioned the link of this thread. Did you clicked on it?

     

    Thanks,

    Green4ever

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points