c# - Indent multiple lines of text -


i need indent multiple lines of text (in contrast this question single line of text).

let's input text:

first line   second line last line 

what need result:

    first line       second line     last line 

notice indentation in each line.

this have far:

var texttoindent = @"first line   second line last line."; var splittedtext = texttoindent.split(new string[] {environment.newline}, stringsplitoptions.none); var indentamount = 4; var indent = new string(' ', indentamount); var sb = new stringbuilder(); foreach (var line in splittedtext) {     sb.append(indent);     sb.appendline(line); } var result = sb.tostring(); 

is there safer/simpler way it?

my concern in split method, might tricky if text linux, mac or windows transfered, , new lines might not splitted correctly in target machine.

since indenting lines, how doing like:

var result = indent + texttoindent.replace("\n", "\n" + indent); 

which should cover both windows \r\n , unix \n end of lines.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -