c# - Output file is not creating a single gap after header -
i generating text file using c# application , wondering why output not giving me single row gap after header row. well, input text file have single row gap after conversion couldn't see single row gap. please help me out.
code snippet:-
public void just_create_text() { //here exporting header string[] strlines = system.io.file.readalllines(textbox1.text); string carouselname = enter.text; int[] cols = new int[] { 15, 15, 25, 15, 15 }; stringbuilder sb = new stringbuilder(); string line = removewhitespace(strlines[0]).trim(); string[] cells = line.replace("\"", "").split('\t'); (int c = 0; c < cells.length; c++) sb.append(cells[c].replace(" ", "_").padright(cols[c])); // here replacing space underscore... sb.append("location".padright(15)); sb.append("\r\n"); int tmpcarousel = 0; int carouselnumber = 0; dictionary<string, int> namesforcarousels = new dictionary<string, int>(); (int = 0; < textfile.count; i++) { (int c = 0; c < cells.length; c++) sb.append(textfile[i].cells[c].replace(" ","_").padright(cols[c])); string name = textfile[i].cells[1]; if (namesforcarousels.trygetvalue(name, out tmpcarousel) == false) { carouselnumber++; namesforcarousels[name] = carouselnumber; } var strcorousel = lstmx.find(x => x.max_pn.equals(name)).carousel; strcorousel = (string.isnullorempty(strcorousel)) ? carouselname : strcorousel; sb.append(string.format("{0}:{1}", strcorousel, carouselnumber).padright(15)); sb.append("\r\n"); } system.io.file.writealltext(@"d:\output.txt", sb.tostring()); } private string removewhitespace(string str) { str = str.replace(" ", " "); if (str.contains(" ")) str = removewhitespace(str); homecoming str; } input text file: .txt format
designator max pn footprint center-x(mm) center-y(mm) "ac1" "100-0177" "capc1608n" "7.239" "82.677" "ac2" "100-0177" "capc1608n" "4.445" "85.471" "c1" "100-0211" "0805m - capacitor" "14.745" "45.72" "c2" "100-0230" "capc3225n" "83.388" "58.42" "c3" "100-0145" "capc1608n" "101.543" "73.025" "c10" "100-0145" "capc1608n" "109.163" "73.025" in output text file need below
designator max_pn footprint center-x(mm) center-y(mm) location // <<here single gap>> c66 100-0009 0805m_-_capacitor 90.106 39.37 eeee:1 c24 100-0009 0805m_-_capacitor 64.973 24.067 eeee:1 c25 100-0009 0805m_-_capacitor 106.553 45.657 eeee:1
i don't know why thought you'd blank line in first place. seek adding line output here:
sb.append("location".padright(15)); sb.append("\r\n"); sb.append("\r\n"); even better, utilize sb.appendline() method instead:
sb.appendline("location".padright(15)); sb.appendline(); c# string visual-studio-2010 visual-studio
No comments:
Post a Comment