c# - Changing sepecific text in a specific line in text file -
here text line in aspx file want change
<center><body link=blue vlink=purple class=xl65 onload="processdata();"><form id="mainform" action="http://localhost/xlez/datahandler/submit.aspx" method="post" enctype="multipart/form- data"><input type="hidden" id="hid_extra" name="hid_extra" value="machine_inspection_20140807162226.xlsx||machine_inspection||excavator inspection||excavator inspection|forklift inspection|tractor inspection"/>
my code finds line, want change action of form in line,
here code changes whole line want change specific text
string form_action ="http://\" + request.url.authority+\"/xlez/datahandler/submit.aspx\""; while ((line = sr.readline()) != null) { if (line.contains("form id=\"mainform\"")) { index = count; } count++; } sr.dispose(); } if (index != 0) { var lines = file.readalllines(selected_path); lines[index] = form_action ; file.writealllines(selected_path, lines); }
but replaces whole line action, want change action in line
in code line of code replaces whole line of html code:
lines[index] = form_action ;
you need replace part of string in line. following example:
string form_action ="http://\" + request.url.authority+\"/xlez/datahandler/submit.aspx\""; while ((line = sr.readline()) != null) { if (line.contains("form id=\"mainform\"")) { index = count; } count++; } sr.dispose(); } if (index != 0) { var lines = file.readalllines(selected_path); int start = lines[index].indexof("action"); string newline = lines[index].substring(0, start + 8) + form_action + " " + lines[index].substring(lines[index].indexof("method")); lines[index] = newline; file.writealllines(selected_path, lines); }
your "form_action" variable not hold right value, since escaped " before use request object. should take @ this.
adjusted form-action creation:
string form_action ="http://" + request.url.authority + "/xlez/datahandler/submit.aspx\"";
Comments
Post a Comment