replace

Why is my Perl in-place script exiting with a zero exit code even though it's failing?

こ雲淡風輕ζ 提交于 2021-02-08 15:19:20
问题 I have a one-liner Perl search and replace that looks roughly like this: perl -p -i -e 's/foo/bar/' non-existent-file.txt Because the file doesn't exist (which isn't intentional, but this is part of an automated build script, so I want to protect against that), Perl exits with this error: Can't open non-existent-file.txt: No such file or directory. However, the exit code is still zero: echo $? 0 Am I doing something wrong? Should I be modifying my script, or the way I'm invoking Perl? I was

Converting unicode characters (C#) Testing

六月ゝ 毕业季﹏ 提交于 2021-02-08 10:18:39
问题 I have the following problem I am using an SDK that returns values form a database. The value i need is 4, 6, 7 but the SDK returns "\u0004","\u0006","\u0007" I was wondering if there is a way to check if it is "\u0004","\u0006","\u0007" or any way of doing this? I Have the following code (C#): Line_Type = Line_Type.Replace(@"\u000", ""); if (Line_Type == "4") { Line_Type = "4"; } else if (Line_Type == "6") { Line_Type = "6"; } else if (Line_Type == "7") { Line_Type = "7"; } I have tried

REPLACE CHAR(0) NVARCHAR Latin1_General_CI_AS collation

天涯浪子 提交于 2021-02-08 06:36:39
问题 In SQL Server I am trying to replace CHAR(0) with '' but it is not working as my field is actually a NVARCHAR field, my collation is Latin1_General_CI_AS but when I convert to SQL_Latin1_General_CP1_CI_AS it only works for VARCHAR and not NVARCHAR . SELECT val, REPLACE(val , CHAR(0), 'x') FROM ( SELECT 'a' + CHAR(0) + 'b' AS val ) AS X Returns a | a SELECT val, REPLACE(CAST(val COLLATE SQL_Latin1_General_CP1_CI_AS AS varchar(100)), CHAR(0), 'x') FROM ( SELECT 'a' + CHAR(0) + 'b' AS val ) AS X

smarty replace multiple values

假如想象 提交于 2021-02-08 02:06:14
问题 I have ..tpl file with this line: {$error|replace:"pno":"personal number error"} I need to modify it so multiple values will be replaced, sort of: {$error|replace:"pno_error":"personal number error", "error_1":"1", "error_2":"2"} I need to make sure the code is correctly formed. How do I achieve this? 回答1: Like so {assign "find" array('pno', 'error_1', 'error_2')} {assign "repl" array('personal number error', 1, 2)} {assign "text" 'error_1 and pno and error_2 are friends'} {$text|replace:

Read a text file, replace its words, output to another text file

喜你入骨 提交于 2021-02-07 18:47:54
问题 So I am trying to make a program in GO to take a text file full of code and convert that into GO code and then save that file into a GO file or text file. I have been trying to figure out how to save the changes I made to the text file, but the only way I can see the changes is through a println statement because I am using strings.replace to search the string array that the text file is stored in and change each occurrence of a word that needs to be changed (ex. BEGIN -> { and END -> }). So

PHP - replace all non-alphanumeric chars for all languages supported

二次信任 提交于 2021-02-07 17:54:29
问题 Hi i'm actually trying replacing all the NON-alphanumeric chars from a string like this: mb_ereg_replace('/[^a-z0-9\s]+/i','-',$string); first problem is it doesn't replaces chars like "." from the string. Second i would like to add multybite support for all users languages to this method. How can i do that? Any help appriciated, thanks a lot. 回答1: Try the following: preg_replace('/[^\p{L}0-9\s]+/u', '-', $string); When the u flag is used on a regular expression, \p{L} (and \p{Letter} )

Running replace() method in a for loop?

◇◆丶佛笑我妖孽 提交于 2021-02-07 14:30:35
问题 Its late and I have been trying to work on a simple script to rename point cloud data to a working format. I dont know what im doing wrong as the code at the bottom works fine. Why doesnt the code in the for loop work? It is adding it to the list but its just not getting formatted by the replace function. Sorry I know this isnt a debugger but I am really stuck on this and it would probably take 2 seconds for someone else to see the problem. # Opening and Loading the text file then sticking

Regex Find Spaces between single qoutes and replace with underscore

老子叫甜甜 提交于 2021-02-07 14:28:29
问题 I have a database table that I have exported. I need to replace the image file name with a space and would like to use notepad++ and regex to do so. I have: 'data/green tea powder.jpg' 'data/prod_img/lumina herbal shampoo.JPG' 'data/ALL GREEN HERBS.jpeg' 'data/prod_img/PSORIASIS KIT (640x530) (2).jpg' and need to make them look like this: 'data/green_tea_powder.jpg' 'data/prod_img/lumina_herbal_shampoo.JPG' 'data/ALL_GREEN_HERBS.jpeg' 'data/prod_img/PSORIASIS_KIT_(640x530)_(2).jpg' I just

Running replace() method in a for loop?

醉酒当歌 提交于 2021-02-07 14:27:14
问题 Its late and I have been trying to work on a simple script to rename point cloud data to a working format. I dont know what im doing wrong as the code at the bottom works fine. Why doesnt the code in the for loop work? It is adding it to the list but its just not getting formatted by the replace function. Sorry I know this isnt a debugger but I am really stuck on this and it would probably take 2 seconds for someone else to see the problem. # Opening and Loading the text file then sticking

REPLACE versus INSERT in SQL

醉酒当歌 提交于 2021-02-07 11:17:10
问题 I am doing the following SQL tutorial: http://sql.learncodethehardway.org/book/ex11.html and in this exercise the author says in the second paragraph: In this situation, I want to replace my record with another guy but keep the unique id. Problem is I'd have to either do a DELETE/INSERT in a transaction to make it atomic, or I'd need to do a full UPDATE. Could anyone explain to me what the problem is with doing an UPDATE, and when we might choose REPLACE instead of UPDATE? The UPDATE code: