How to add a new line in Replace Text

nambu

Avatar of nambu

  • Joined: Jan 7, 2010
  • Posts: 21

  • Participant

Thu 03/06/2010 at 15:21

I’m trying to use the Replace Text action to add variables to a PHP file. I want each new variable to be on a new line. The way I have it setup is like this:

$variable1 = "whatever";

//add new var

I replace the text "//add new var" with the new variable to be added. But I also need to add "//add new var" on the next line so as to add other variables in the future.

I tried something like this, Replace With: $variable2 = "whatever2";n//add new line

But it doesn’t make n into a new line. I tried checking the box "Use Regular Expressions for find and replace" but got the same result. Is it possible to make a new line using the Replace Text action?

#1

D.M.Altizer

Avatar of D.M.Altizer

  • Joined: Jan 12, 2010
  • Posts: 204

  • Participant

Fri 04/06/2010 at 13:42

 Hello there! You cannot use r?n in the replacement string of regular expressions (you can see that if you try to do a replacement with r?n in Expresso) . There are 2 alternatives that you may want to consider:

– You can use the "Append Line To Text" action (under "Text Actions" category):
Most people don’t know the specific action and it can help you with the issue that you are facing.

– You can also use the "Split Text" action with custom delimiter (i.e. the text that you want to replace) and "Join Text" with standard delimiter (i.e. NewLinex1).

==Dedicated Automation Solutions==
#2

nambu

Avatar of nambu

  • Joined: Jan 7, 2010
  • Posts: 21

  • Participant

Tue 08/06/2010 at 12:00

Hi, thanks for your reply! At first I wasn’t quite sure how to implement the "Append Line To Text" action to accomplish what I needed. I hadn’t thought about using it to append the new line to the variable I’m adding to the file. When I did it like that, it worked perfectly.

So to anyone who may stumble upon this thread and isn’t sure about "Append Line To Text", I’ll try to give a brief example:

"Set Variable"
Set Value: $link2 = "http://link2.com";
into Variable: %NewLink%

"Append Line To Text"
Original Text: %NewLink%
Line to Append: // add new link
Store Result Into: %NewLink%

Then Replace Text: // add new link with %NewLink%

$link1 = "http://link1.com";
// add new link

becomes…

$link1 = "http://link1.com";
$link2 = "http://link2.com";
// add new link

Thanks D.M.Altizer

#3

D.M.Altizer

Avatar of D.M.Altizer

  • Joined: Jan 12, 2010
  • Posts: 204

  • Participant

Wed 09/06/2010 at 11:20

 Glad that I could help :)

I think (and I say that without providing any guarantee at all :P) that the "Replace With" field of the "Replace Text" action will become a multi-line field allowing you to enter something like the following:

%"
"%

and replace the text that you selected with a new line character. This is not a part of the first beta that has been released but it was mentioned by an employee of the support department in one of the emails that I sent to them.

==Dedicated Automation Solutions==
#4

You must be logged in to reply to this topic.

Viewing 4 posts - 1 through 4 (of 4 total)