winforms - How to replace multiple texts in a file in c#? -


i automating process using c#. script below,

 update   table  set   param_val = replace(param_val,'proxy430/','proxy440/')    param_key = 'proxy_url';    update   table   set   param_val = replace (param_val, '.420/', '.430/')    param_val '%.420/%';   

for every month, upgrade version 44 in place of 43 , 43 in place of 42 , run script. automate, i've written c# code , used below code

string text = file.readalltext(filepath); text.replace(oldvale, newvalue); file.writealltext(filepath, text); 

but, issue can replace 1 word only. how replace 2 texts in file. in case, proxy430 should replaced proxy440 , proxy440 proxy450 in single shot.

how achieve this?

if call replace in right order can accomplish 2 replacements on single line.

string teststring = @"update   table set param_val = replace(param_val, 'proxy430/', 'proxy440/') param_key = 'proxy_url';  update table set param_val = replace(param_val, '.420/', '.430/') param_val '%.420/%'; ";  const string oldfrom = "proxy430"; const string oldto = "proxy440"; const string newfrom = "proxy440"; const string newto = "proxy450";  string result = teststring.replace(newfrom, newto).replace(oldfrom, oldto); console.writeline(result); 

the output is:

update   table  set param_val = replace(param_val, 'proxy440/', 'proxy450/')  param_key = 'proxy_url';  update table  set param_val = replace(param_val, '.420/', '.430/')  param_val '%.420/%'; 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -