replace

Write values of Python dictionary back to file

一曲冷凌霜 提交于 2020-01-11 11:45:48
问题 I extracted information from two XML files into 2 dictionaries because I wanted to compare these files and change information in one of them. These are my dictionaries: source dictionary: d_source={'123': 'description_1', '456': 'description_2'} target dictionary: d_target={'123': '\n', '456': 'description_2'} This is my replacement code: for i in d_source: for j in d_target: if d_target[j]=='\n': d_target[j]=d_source[i] print (d_target) d_target is updated to d_target = {'123': 'description

How to replace specific characters with corresponding characters in java? [duplicate]

你离开我真会死。 提交于 2020-01-11 11:36:01
问题 This question already has answers here : Most efficient way to use replace multiple words in a string [duplicate] (4 answers) Closed 2 years ago . I want to do something like this: Replace all ck with k and all dd with wr and all f with m and 10 more replacements like this. I can do it with replace("ck","k").replace("dd","wr") and so on, but it seams silly and it is slow. Is there any function in java that does something like this? for example replace(string,stringArray1, stringArray2); 回答1:

How to replace specific characters with corresponding characters in java? [duplicate]

混江龙づ霸主 提交于 2020-01-11 11:35:08
问题 This question already has answers here : Most efficient way to use replace multiple words in a string [duplicate] (4 answers) Closed 2 years ago . I want to do something like this: Replace all ck with k and all dd with wr and all f with m and 10 more replacements like this. I can do it with replace("ck","k").replace("dd","wr") and so on, but it seams silly and it is slow. Is there any function in java that does something like this? for example replace(string,stringArray1, stringArray2); 回答1:

Find a line in a file and replace the next line

落爺英雄遲暮 提交于 2020-01-11 11:18:56
问题 Using a .bat script, I want to find a line that says # Site 1 and replace the text in the next line with a variable. I found tutorials on StackOverflow for finding and replacing a line, but not finding a line and replacing the next line. Any help? 回答1: @echo off set "the_file=C:\someFile" set "search_for=somestring" set "variable=http://site1" for /f "tokens=1 delims=:" %%# in ('findstr /n /c:"%search_for%" "%the_file%"') do ( set "line=%%#" goto :break ) :break set /a lineBefore=line-1 set

android SQLite update/insert

旧城冷巷雨未停 提交于 2020-01-11 11:18:24
问题 I want to UPDATE a row in my table, WHERE key = LastSelected If a row with that key does not exist, I want to INSERT it. I can get the UPDATE to work if the row already exists, but it will not INSERT if it is missing. I have tried these (the first one correctly updates, but does not insert) : String.format("UPDATE table_1 SET value = '%s' WHERE key = 'LastSelected'", s); String.format("REPLACE table_1 SET value = '%s' WHERE key = 'LastSelected'", s); String.format("INSERT OR REPLACE INTO

Find a line in a file and replace the next line

淺唱寂寞╮ 提交于 2020-01-11 11:18:03
问题 Using a .bat script, I want to find a line that says # Site 1 and replace the text in the next line with a variable. I found tutorials on StackOverflow for finding and replacing a line, but not finding a line and replacing the next line. Any help? 回答1: @echo off set "the_file=C:\someFile" set "search_for=somestring" set "variable=http://site1" for /f "tokens=1 delims=:" %%# in ('findstr /n /c:"%search_for%" "%the_file%"') do ( set "line=%%#" goto :break ) :break set /a lineBefore=line-1 set

SQLite Insert OR update without losing record data

人走茶凉 提交于 2020-01-11 11:02:34
问题 i have a table "test" with primary keys on "id & "lang" ╔════╦══════╦══════╦═══════╗ ║ id ║ lang ║ test ║ test2 ║ ╠════╬══════╬══════╬═══════╣ ║ 1 ║ zh ║ lol3 ║ lol4 ║ ║ 1 ║ en ║ lol ║ qsdf ║ ╚════╩══════╩══════╩═══════╝ and i want to do insert or update but since you cannot do IF statement im left out with INSER OR REPLACE INTO when i run my query : INSERT OR REPLACE INTO test (id,lang,test) VALUES (1,'en','zaki') i get this ╔════╦══════╦══════╦════════╗ ║ id ║ lang ║ test ║ test2 ║ ╠════╬══

Replacing Text in a child under parent DIV through JQuery

点点圈 提交于 2020-01-11 10:54:26
问题 I want to change text of (Access denied. Please Login or Register.) to "You are not authorized to access" in the following code:- <div class="messages error"> <h2 class="element-invisible">Error message</h2> Access denied. Please Login or Register. </div> I tried using the following code in on Ready Function, but it isn't working correctly. $("div.messages").text(function () { console.log($(this).text()); return $(this).text().replace("Access denied. Please Login or Register.", "You are not

preg_replace how surround html attributes for a string with " in PHP

廉价感情. 提交于 2020-01-11 10:26:15
问题 I have a string variable in PHP , its content is: $var='<SPAN id=1 value=1 name=1> one</SPAN> <div id=2 value=2 name=2> two</div >'; .... I need a function for surround html attributes with "" i need do this for the all meta-tag ,etc the result should be this: $var='<SPAN id= "1" value="1" name="1"> one </SPAN> <div id="2" value="2" name="2" > two</div >'; ... I need replace all =[a-z][A-Z][1-9] for ="[a-z][A-Z][1-9]". I need a regular expresion for preg_replace 回答1: You need to wrap it all

PHP regular expression to replace nested () with []

我与影子孤独终老i 提交于 2020-01-11 10:25:14
问题 I am trying to match a string, see example, such that a nested parantheses () is replaced by [] so to not break a parser somewhere else. In this case, I would like to replace the $myStr with "Arman; Dario (10040 Druento (Turin), IT)" ... Thanks in advance! monte {x: $myStr = "Arman; Dario (10040 Druento (Turin), IT)"; $pattern = "/(\()([a-z,A-Z0-9_\&\/\'\-\,\;\:\.\s^\)]+)(\))/"; if (preg_match_all($pattern,$myStr,$matches)) { print_r($matches); } Obviously, I also need to switch match_all to