Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c# string to html keeping whitespace?

Tags:

html

c#

I feel like I must be missing a keyword or something when searching since I can't seem to find anyone else looking for this....

I have a string in c# that has line breaks, spaces, tabs etc and I want to display it on my html page in MVC, but keep the formatting instead of losing all the whitespace.

I first used some regex to put line breaks in, but before moving on to try and replace all other possible white space with the appreciate spacing in html, it seems like there would be a class or library already built to do this.

Does anyone know how I can easily convert a c# string to html and keep the white space?

Thanks.

like image 708
Kyle Avatar asked Sep 12 '12 05:09

Kyle


1 Answers

just render it inside of a <pre> tag

like image 155
guy schaller Avatar answered Oct 16 '22 11:10

guy schaller