replace

Replace text that appears at the end of a string

坚强是说给别人听的谎言 提交于 2020-01-03 17:45:31
问题 Consider "artikelnr" . I want to replace "nr" by "nummer" , but when I consider "inrichting" , I do NOT want to replace "nr" . So I just want to replace "nr" by "nummer" if it's at the end of a word. 回答1: regex is your friend, here: sub('nr$', 'nummer', 'artikelnr') # [1] "artikelnummer" The $ indicates "end of string", so nr will only be replaced with nummer when it appears at the end of the string. sub can operate on an entire vector, e.g. for a character vector x , do: sub('nr$', 'nummer',

MySQL REPLACE in an auto incremented row

时光毁灭记忆、已成空白 提交于 2020-01-03 17:34:09
问题 Let say I have a MySQL table which contains three columns: id , a and b and the column named id is an AUTO INCREMENT field. If I pass a query like the following to MySQL, it will works fine: REPLACE INTO `table` (`id`, `a`, `b`) VALUES (1, 'A', 'B') But if I skip the field id it will no longer works, which is expected. I want to know if there is a way to ignore some fields in the REPLACE query. So the above query could be something like this: REPLACE INTO `table` (`a`, `b`) VALUES ('A', 'B')

find and replace values in cell array

最后都变了- 提交于 2020-01-03 17:10:59
问题 I have a cell array like this: [... 0 129 8...2...3...4 6...4 0 I just want to find and replace specific values, but I can't use the ordinary function because the cells are different lengths. I need to replace many specific values at the same time and there is no general function about how values are replaced. However, sometimes several input values should be replaced by the same output. so I want to say for values 1:129 'if 0, then 9' 'elseif 1 then 50' 'elseif 2 or 3 or 4 then 61' etc...up

Find/replace string with carriage return and line feed in PowerShell

冷暖自知 提交于 2020-01-03 17:08:22
问题 Is there a way to have PowerShell find and replace a string (for example ~}}|{{E ) with a carriage return and line feed ( \r\nE )? For example: $filenames = @("E:\blergfest.csv") foreach ($file in $filenames) { $outfile = "$file" + ".out" Get-Content $file | Foreach-object { $_ -replace '\~}}|{{E', '\r\nE' ` -replace '\|\r\n', '\r\n' } | Set-Content $outfile } powershell control-characters share | improve this question 回答1: How about this: $filenames = @("E:\blergfest.csv") foreach ($file in

replacing newline sed

扶醉桌前 提交于 2020-01-03 15:13:20
问题 How to replace \n from a line using sed command? 回答1: It's gross, because sed normally processes a line at a time: sed -e :a -e N -e 's/\n/ /' -e ta input.txt This is nicer: tr '\n' ' ' < input.txt I chose to replace the newline with a space. tr can only replace by a single character (or delete with the -d option). Flexible and simple: perl -ne 'chomp;print $_," "' input.txt Where " " is whatever you want in place of the newline. 来源: https://stackoverflow.com/questions/1442702/replacing

How to detect and replace non-printable characters in a string using Java?

空扰寡人 提交于 2020-01-03 13:57:22
问题 For instance I have a string like this : abc123[*]xyz[#]098[~]f9e [*] , [#] and [~] represents 3 different non-printable characters. How can I replace them with "X" in Java ? Frank 回答1: I'm not sure if I understand your questions. If you can formulate it better, I think a simple regular expression replacement may be all that you need. String r = s.replaceAll(REGEX, "X"); REGEX depends on what you need: "\\*|#|~" : matches only '*', "#', and '~' "[^\\d\\w]" : matches anything that is neither a

sed doesn't work from within bash script

情到浓时终转凉″ 提交于 2020-01-03 13:03:13
问题 I've searched for hours looking for the answer to this question which seems frustratingly simple... I have a bash script which I've simplified to find the line that's stopping it from working and am left with: #!/bin/bash # sed -i -e "s/<link>/\n/g" /usb/lenny/rss/tmp/rss.tmp If I run this script, nothing happens to the file rss.tmp - but if I call this exact same sed command from the terminal, it makes all the replacements as expected. Anyone have any idea what I'm doing wrong here? 回答1:

Find and replace a string in multiple files using Batch script

微笑、不失礼 提交于 2020-01-03 12:30:14
问题 I have more 3000 files in a folder. I want to find and replace text with another one. How can I do that? I'm a newbie in batch script. I can replace it in 1 file but I don't know how to replace in multiple files. FOR /F %%L IN (lala.txt) DO ( SET "line=%%L" SETLOCAL ENABLEDELAYEDEXPANSION set "x=!line:E:\Test=E:\Test\Temp!" echo f | xcopy /E !line! !x! ENDLOCAL ) How can I edit my code to replace the string in all files? Waiting for your help. Thanks 回答1: Install the Find And Replace Text

Regexp-replace: Multiple replacements within a match

倖福魔咒の 提交于 2020-01-03 11:25:09
问题 I'm converting our MVC3 project to use T4MVC. And I would like to replace java-script includes to work with T4MVC as well. So I need to replace "~/Scripts/DataTables/TableTools/TableTools.min.js" "~/Scripts/jquery-ui-1.8.24.min.js" Into Scripts.DataTables.TableTools.TableTools_min_js Scripts.jquery_ui_1_8_24_min_js I'm using Notepad++ as a regexp tool at the moment, and it is using POSIX regexps. I can find script name and replace it with these regexps: Find: \("~/Scripts/(.*)"\) Replace with

Replacing digits with str.replace()

混江龙づ霸主 提交于 2020-01-03 09:04:14
问题 I want to make a new string by replacing digits with %d for example: Name.replace( "_u1_v1" , "_u%d_v%d") ...but the number 1 can be any digit for example "_u2_v2.tx" Can I give replace() a wildcard to expect any digit? Like "_u"%d"_v"%d".tx" Or do I have to make a regular expression? 回答1: Using regular expressions: >>> import re >>> s = "_u1_v1" >>> print re.sub('\d', '%d', s) _u%d_v%d \d matches any number 0-9. re.sub replaces the number(s) with %d 回答2: You cannot; str.replace() works with