Questions tagged [substitution]

The action of replacing something with another thing.

The action of replacing something with another thing.

1879 questions
20
votes
3 answers

How to get name of variable in R (substitute)?

I stacked with trying to pass variable through few functions, and on the final function I want to get the name of the original variable. But it seems like substitute function in R looked only in "local" environment, or just for one level up. Well,…
EvilAnton
  • 353
  • 1
  • 2
  • 9
18
votes
2 answers

Substitution in a file name with reStructuredText (Sphinx)?

I want to create several files from a single template, which differ only by a variable name. For example : (file1.rst): .. |variable| replace:: 1 .. include template.rst (template.rst) : Variable |variable| ===================== Image ------- ..…
pierre
  • 770
  • 7
  • 14
18
votes
1 answer

How to split text into multiple lines based on a pattern using Vim?

Suppose you have this text: name1 = "John"; age1 = 41; name2 = "Jane"; age2 = 32; name3 = "Mike"; age3 = 36; ... and you want to split each line into two lines to give a result like this: name1 = "John"; age1 = 41; name2 = "Jane"; age2 = 32; name3…
Ori Popowski
  • 10,432
  • 15
  • 57
  • 79
17
votes
1 answer

Maven: property substitution not done for /project/version tag of pom?

http://maven.apache.org/pom.html#Properties says property "values are accessible anywhere within a POM". Should this read "are accessible in most places within a POM"? I can specify the version of a dependency no problem like so:
George Hawkins
  • 37,044
  • 7
  • 30
  • 43
17
votes
1 answer

string variable not substituted in multi-line string

Here is the code/output all in one: PS C:\code\misc> cat .\test.ps1; echo ----; .\test.ps1 $user="arun" $password="1234*" $jsonStr = @" { "proxy": "http://$user:$password@org.proxy.com:80", "https-proxy":…
deostroll
  • 11,661
  • 21
  • 90
  • 161
16
votes
7 answers

Iterating through array in SendGrid email template

I'm trying to iterate through a collection and display information in a SendGrid template using Ruby on Rails. recipient = SendGrid::Recipient.new("sergio@gmail.com") recipient.add_substitution("username",…
Sergio Tapia
  • 9,173
  • 12
  • 35
  • 59
15
votes
3 answers

Python Regex escape operator \ in substitutions & raw strings

I don't understand the logic in the functioning of the scape operator \ in python regex together with r' of raw strings. Some help is appreciated. code: import re text=' esto .es 10 . er - 12 .23 with [ and.Other ] here is more ;…
JFerro
  • 3,203
  • 7
  • 35
  • 88
15
votes
6 answers

Inline regex replacement in perl

Is there a way to replace text with a regex inline, rather than taking the text from a variable and storing it in a variable? I'm a perl beginner. I often find myself writing my $foo = $bar; $foo =~ s/regex/replacement/; doStuff($foo) where I'd…
Charles
  • 11,269
  • 13
  • 67
  • 105
14
votes
2 answers

How do I avoid repetition in Java ResourceBundle strings?

We had a lot of strings which contained the same sub-string, from sentences about checking the log or how to contact support, to branding-like strings containing the company or product name. The repetition was causing a few issues for ourselves…
Hakanai
  • 12,010
  • 10
  • 62
  • 132
14
votes
2 answers

How do I use the C preprocessor to make a substitution with an environment variable

In the code below, I would like the value of THE_VERSION_STRING to be taken from the value of the environment variable MY_VERSION at compile time namespace myPluginStrings { const char* pluginVendor = "me"; const char* pluginRequires = …
Julian Mann
  • 6,256
  • 5
  • 31
  • 43
14
votes
1 answer

Substitution with empty string: unexpected result

Why are the two printed numbers different? #!/usr/bin/env perl use warnings; use 5.10.1; my $sep = ''; my $number = 110110110110111; $number =~ s/(\d)(?=(?:\d{3})+\b)/$1$sep/g; say "A: <$number>"; $number =~ s/\Q$sep\E//g; say "B:…
sid_com
  • 24,137
  • 26
  • 96
  • 187
14
votes
4 answers

Bash eval replacement $() not always equivalent?

Everybody says eval is evil, and you should use $() as a replacement. But I've run into a situation where the unquoting isn't handled the same inside $(). Background is that I've been burned too often by file paths with spaces in them, and so like…
Shenme
  • 1,182
  • 1
  • 13
  • 12
13
votes
3 answers

What does the Perl substitution operator act on?

I have been programming in Perl, off and on, for years now, although only sporadically is it my primary language. Because I often go months without writing any perl, I rely heavily on my dog-eared Camel Book to remind me how to do things. However,…
Ed Hyer
  • 1,385
  • 2
  • 13
  • 19
13
votes
1 answer

How many substitutions took place in a Perl s///g?

Small example: perl -e '$s="aaabbcc";$c=()=$s=~/a/g;print"$c\n$s\n"' (m//g) outputs 3 aaabbcc whereas perl -e '$s="aaabbcc";$c=()=$s=~s/a/x/g;print"$c\n$s\n"' (s///g) outputs 1 xxxbbcc I'd like to do both things at once without having to match…
musiKk
  • 14,751
  • 4
  • 55
  • 82
13
votes
5 answers

Non-sequential substitution in SymPy

I'm trying to use [SymPy][1] to substitute multiple terms in an expression at the same time. I tried the [subs function][2] with a dictionary as parameter, but found out that it substitutes sequentially. In : a.subs({a:b, b:c}) Out: c The problem…
Mad Scientist
  • 18,090
  • 12
  • 83
  • 109