I want to modify a string with replace in Smarty.
{$var|replace:'aaa':'bbb'}
Simple. But I need to replace this:
{$var|replace:'value="AA"':'value="$string_b"'}
I've also tried with the following syntax with no success:
{$var|replace:'value="AA"':'value="'$string_b'"'}
{$var|replace:'value="AA"':'value="`$string_b`"'}
{$var|replace:'value="AA"':'value=""$string_b""'}
you have to enclose the string in double quotes if you want smarty to recognize variables inside, so in your case you also have to escape the double quotes inside the string:
{$var|replace:'value="AA"':"value=\"{$string_b}\""}
Using brackets around the variable is not necessary but recommended
In the end I managed to find the right syntax to use.
{$var|replace:"value=\"AA\"":"value=\"$string\"}
Related
how I could use eval(rlang::parse_expr(string))’ or alternative with such expresssion string <-"print('A\s*B')"`? I am getting unrecognized escape character. The expression is evaluated inside function, print is an example, I am using grepl in similar manier.
Simply using second escape slash helped "print('A\s*B')"
I'm trying to display to a user 'streamlines'. How would I do this?? I've tried using disp() with " inserted with failure.
How would I go about doing this?
Single quotes need to be escaped by placing a single quote in front of them. Something like this:
username = '''streamlines'''
disp(username)
I think you´re asking how to write the apostrophe, right? if is that you just have to double the apostrophe and it will show up like just one. It would be like: ''streamlines''.
Let s = my string
Something like:
set s to quoted form of s
gives 'my string'
Which is only single quotes around the string and something like:
set s to ("\"" & s & "\"")
gives \"my string\"
Which adds the backslashes to the string for some reason.
If you display the string in your last example, you'll see that the script indeed has gotten double quotes around them.
The reason the double quotes are shown with backslashes internally, is that AppleScript needs to make a difference between the literal backslashes, is that you use double quotes, for say assigning a string to a variable. So usual double quotes has a distinct purpose in AppleScript, and it needs to tell a difference between those, and the literal double qoutes that you want to use in any variables. When your literal double quotes are put to display, then they are shown as usual double qoutes, also if they are written into a text file for instance, that you open with an editor, then you'll realize, that AppleScript perform escaping "behind the scenes", into an internal representation, that makes the data work with the conventions of AppleScript, so that any data doesn't break the script, when the script compiles first and foremost.
Try using the code below to display it.
tell application (path to frontmost application as text)
display alert s
end tell
Then you'll realize that you have gotten "normal" double qoutes in your string for display.
What’s the difference between single (') and double (") quotes in Vim? Does it make speed differences? Is it better to use one or another when running functions inside it? Does it matter at all?
I’m interested specifically in their use in the .vimrc file.
I’m asking because I find people use both in the same thing, and I’m wondering what are the differences. I tried to Google this, but wasn’t able to find anything.
Double quotes allow for interpolation whereas single quotes do not.
For example, using double quotes :echo "foo\nbar" will output foo and bar on separate lines whereas :echo 'foo\nbar' will not interpret \n as a line break and will output foo\nbar literally.
For more info on different types of quotes type :h 41.2 for the help file and read the part near the end of the section with the heading STRING VARIABLES AND CONSTANTS.
This said, don't confuse quotes for strings with the double quote at the beginning of a line comment. Single quotes never start line comments, only double quotes do.
I have something akin to <Foobar Name='Hello There'/> and need to change the single quotation marks to double quotation marks. I tried :s/\'.*\'/\"\0\" but it ended up producing <Foobar Name="'Hello There'"/>. Replacing the \0 with \1 only produced a blank string inside the double quotes - is there some special syntax I'm missing that I need to make only the found string ("Hello There") inside the quotation marks assign to \1?
There's also surround.vim, if you're looking to do this fairly often. You'd use cs'" to change surrounding quotes.
You need to use groupings:
:s/\'\(.*\)\'/\"\1\"
This way argument 1 (ie, \1) will correspond to whatever is delimited by \( and \).
%s/'\([^']*\)'/"\1"/g
You will want to use [^']* instead of .* otherwise
'apples' are 'red' would get converted to "apples' are 'red"
unless i'm missing something, wouldn't s/\'/"/g work?
Just an FYI - to replace all double quotes with single, this is the correct regexp - based on rayd09's example above
:%s/"\([^"]*\)"/'\1'/g
You need to put round brackets around the part of the expression you wish to capture.
s/\'\(.*\)\'/"\1"/
But, you might have problems with unintentional matching. Might you be able to simply replace any single quotes with double quotes in your file?
You've got the right idea -- you want to have "\1" as your replace clause, but you need to put the "Hello There" part in capture group 1 first (0 is the entire match). Try:
:%/'\(.*\)'/"\1"
Shift + V to enter visual block mode. Highlight the lines of code you want to remove single quotes from.
Then hit : on keyboard
Then type
s/'//g
Press Enter.
Done. You win.
Presuming you want to do this on an entire file ...
N Mode:
ggvG$ [SHIFT+:]
X Mode:
'<,'>/'/" [RET]