c# - How to remove substring from each line of text file -


this question exact duplicate of:

let's have data in following format...

<sdf<xml>....</xml>... .........<smc<xml>.... ...</xml>...<ueo<xml>. .... , goes on...... 

my objective read data line line file , delete 4 preceding characters before <xml> tag detected. in above case, <sdf, <smc , <ueo deleted.

i've written following right now.. regex @ moment wrong , not working..

while((line = reader.readline()) !=null) {   writer.writeline(regex.replace(line, @"(?i)</(xml)(?!>)",</$1>),, string.empty);          } 

your general idea , loop structure fine. it's regex matching needs little work:

while ((line = reader.readline()) != null)     writer.writeline(regex.replace(line, @"....<xml>", "<xml>")); 

if want work pattern of form <...<tag> can use:

while ((line = reader.readline()) != null)     writer.writeline(regex.replace(line, @"<[^<>]{3}<([^<>]+)>", "<$1>")); 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -