C# Insert multiline text in string at certain position -


i have multiline string in want append multiline text , keep indentation appended lines of text. example explains issue better:

stringbuilder sb = new stringbuilder(); int int1 = 50000; double double1 = 5800.0; string test = "test\r\nsome\r\nmultiline\r\nstuff."; sb.appendformat("{0,8};{1,8};{2}",int1,double1,test); console.write(sb.tostring()); 

this give me output

50000;    5800;test multiline stuff. 

however wish attain

50000;    5800;test                               multiline                stuff. 

i'm aware there ways handle writing own functionality, hoping stringbuilder class or similar construct me.

you can use system.codedom.compiler.indentedtextwriter easy solution. worth knowing type anyway, if have generate source code or such frequently.

in end, system.text.stringbuilder, used, demo code shows:

static void bar() {     int int1 = 50000;     double double1 = 5800.0;     string test = "test\r\nsome\r\nmultiline\r\nstuff.";      stringbuilder sb = new stringbuilder();     stringwriter writer = new stringwriter(sb);     indentedtextwriter itw = new indentedtextwriter(writer, new string(' ', 18));     itw.write("{0,8};{1,8};", int1, double1);     itw.indent++;     test.split(new char[] { '\n' }).all(s => { itw.writeline(s); return true; });     console.write(sb.tostring()); } 

Comments

Popular posts from this blog

1111. appearing after print sequence - php -

node.js - Express and Redis - If session exists for this user, don't allow access -

excel - I can't get the attachement of the email PHP -