substitution

How to substitute a special character between words in R [duplicate]

假如想象 提交于 2019-11-29 16:17:54
This question already has an answer here: How to replace many special characters with “something plus special characters” in R 3 answers I have a string of characters. str = c(".wow", "if.", "not.confident", "wonder", "have.difficulty", "shower") I am trying to replace "." in between words with a whitespace. So it would look like this ".wow", "if.", "not confident", "wonder", "have difficulty", "shower" First, I tried gsub("[\\w.\\w]", " ", str) [1] " o " "if" "not confident" " onder" [5] "have difficulty" "sho er " It gave me the whitespace I want, but chopped off all the w's. Then, I tried

How do I substitute from a list of strings in VIM?

五迷三道 提交于 2019-11-29 14:11:22
I am a vim user, and I want to be able to loop over a range of substrings when I am substituting. How can I use some vim magic to go from a set of lines like this: Afoo Bfoo Cfoo Dfoo to Abar Bbar Cbaz Dbaz ? I want to search my file from the start for the next occurance of foo , and replace the first two instances with bar , and the second two with baz . Is using a for loop the best option? If so, then how do I use the loop variable in the substitution command? I would use a function that has a state, and call this function from %s. Something like: " untested code function! InitRotateSubst()

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

我与影子孤独终老i 提交于 2019-11-29 13:51:57
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 = THE_VERSION_STRING; }; So that if I type: export MY_VERSION="2010.4" pluginRequires will be set at "2010.4", even if MY_VERSION is set to something else at run time. UPDATE: (feb 21) Thanks for your help everyone. It works. As I'm using Rake as a build system, each of my CFLAGS is a ruby variable. Also the values need to end up in quotes. Therefore the gcc

Bash variable substitution on find's output through exec

折月煮酒 提交于 2019-11-29 11:15:25
Is there any way to apply bash variable substitution on find 's output? I know I've seen some one do it on stack overflow but I can't seem to find that particular post anymore. As an example , let's say I want to rename files *.png to *_copy.png . I know I can do this using rename but it's just a thought experiment. Now I'd like to be able to do something like this: find . -name "*png" -exec mv "{}" "${{}%.*}_copy.png" \; Which results in an invalid substitution . Of course, I could first assign the output to a variable and then apply substitution in a sub-shell, but is this really the only

How can I substitute the nth occurrence of a match in a Perl regex?

亡梦爱人 提交于 2019-11-29 11:13:03
Following up from an earlier question on extracting the n'th regex match , I now need to substitute the match, if found. I thought that I could define the extraction subroutine and call it in the substitution with the /e modifier. I was obviously wrong (admittedly, I had an XY problem ). use strict; use warnings; sub extract_quoted { # à la codaddict my ($string, $index) = @_; while($string =~ /'(.*?)'/g) { $index--; return $1 if(! $index); } return; } my $string = "'How can I','use' 'PERL','to process this' 'line'"; extract_quoted ( $string, 3 ); $string =~ s/&extract_quoted($string,2)/'Perl'

All possible combinations of selected character substitution in a string in ruby

跟風遠走 提交于 2019-11-29 08:03:21
I was wondering if there is a simple way to do every combination of selected character substitutions in ruby in a simple way. An example: string = "this is a test" subs = ['a'=>'@','i'=>'!','s'=>'$'] subs.combination.each { |c| string.gsub c } would yield "this is @ test" "th!s !s a test" "thi$ i$ a te$t" "th!s !s @ test" "thi$ i$ @ te$t" "th!$ !$ a te$t" "th!$ !$ @ te$t" Thanks for the help! string = "this is a test" subs = ['a'=>'@','i'=>'!','s'=>'$'] subs = subs.first.map(&:to_a) 1.upto(subs.length).each do |n| subs.combination(n).each do |a| p a.each_with_object(string.dup){|pair, s| s

How to use ASP.Net server controls inside of Substitution control?

▼魔方 西西 提交于 2019-11-29 07:40:14
while the method we use in Substitution control should return strings, so how is it possible to use a donut caching in web forms on a server control which should be rendered server side? for example Loginview control? Micah UPDATE This is now a fully working example. There a few things happening here: Use the call back of a substitution control to render the output of the usercontrol you need. Use a custom page class that overrides the VerifyRenderingInServerForm and EnableEventValidation to load the control in order to prevent errors from being thrown when the usercontrol contains server

How to make sed remove lines not matched by a substitution

纵饮孤独 提交于 2019-11-29 05:29:40
I basically want to do this: cat file | grep '<expression>' | sed 's/<expression>/<replacement>/g' without having to write the expression twice: cat file | sed 's/<expression>/<replacement>/g' Is there a way to tell sed not to print lines that does not match the regular expression in the substitute command? jaypal singh Say you have a file which contains text you want to substitute. $ cat new.text A B If you want to change A to a then ideally we do the following - $ sed 's/A/a/' new.text a B But if you don't wish to get lines that are not affected with the substitution then you can use the

Substitutions inside links in reST / Sphinx

我的梦境 提交于 2019-11-28 19:29:38
I am using Sphinx to document a webservice that will be deployed in different servers. The documentation is full of URL examples for the user to click and they should just work. My problem is that the host, port and deployment root will vary and the documentation will have to be re-generated for every deployment. I tried defining substitutions like this: |base_url|/path .. |base_url| replace:: http://localhost:8080 But the generated HTML is not what I want (doesn't include "/path" in the generated link): <a href="http://localhost:8080">http://localhost:8080</a>/path Does anybody know how to

Vim - incremental numbering via regular expression search and replace

拜拜、爱过 提交于 2019-11-28 13:09:15
I have this code: array ('id' => 1, 'name' => "Murka", 'date_of_birth' => "2014-10-31", "breed_id" => 1), array ('id' => 1, 'name' => "Jurka", 'date_of_birth' => "2014-11-31", "breed_id" => 2), array ('id' => 1, 'name' => "Nyash", 'date_of_birth' => "2014-12-31", "breed_id" => 3), array ('id' => 1, 'name' => "Meowy", 'date_of_birth' => "2014-01-31", "breed_id" => 4), array ('id' => 1, 'name' => "Yummi", 'date_of_birth' => "2014-10-31", "breed_id" => 2), array ('id' => 1, 'name' => "Barss", 'date_of_birth' => "2014-05-31", "breed_id" => 2), array ('id' => 1, 'name' => "Nonam", 'date_of_birth' =