How to add a new line in Replace Text
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?
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).
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 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
Glad that I could help
I think (and I say that without providing any guarantee at all ) 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.
You must be logged in to reply to this topic.