|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
save string var to html file without losing formatI am using StreamWriter class to save string var into html file but somehow when I open the html file all formats are lost. I want to keep all formats(spaces, newline and so on)For example, I have sFunc in below format(newline, spaces ...) ----------sFunc ---------------- Function ABC(byval a as integer) as integer If a > 0 then x = 1 else x = 2 end if End Function -----------sFunc ----------------- but when I save it to f.html file using streamwriter I see the following when I open the file by doubleclicking. -------------what i see---------------- Function ABC(byval a as integer) as integerIf a > 0 thenx = 1elsex = 2end ifEnd Function -------------what i see---------------- Here is the code snippet ------------------------- Dim sw As StreamWriter = New StreamWriter(Application.StartupPath & "\f.htm", False) sw.AutoFlush = True sBody = m_sFuncBody sw.WriteLine("<html><head>") sw.WriteLine("<body>") sw.WriteLine(sFunc) sw.WriteLine("</body>") sw.WriteLine("</html>") sw.Close() ------------------------- This may be html question but .. any suggestion?
Show quote
Hide quote
"mike" <mikekimh***@gmail.com> schrieb: Put the data inside a 'pre' element, for example. Additionally make sure > I am using StreamWriter class to save string var into html file but > somehow when I open the html file all formats are lost. I want to keep > all formats(spaces, newline and so on)For example, I have sFunc in > below format(newline, spaces ...) > ----------sFunc ---------------- > Function ABC(byval a as integer) as integer > If a > 0 then > x = 1 > else > x = 2 > end if > End Function > -----------sFunc ----------------- > > but when I save it to f.html file using streamwriter I see the > following when I open the file by doubleclicking. > -------------what i see---------------- > Function ABC(byval a as integer) as integerIf a > 0 thenx = 1elsex = > 2end ifEnd Function > -------------what i see---------------- characters like ">" are encoded correctly (">" -> ">"). You can use 'HttpUtility.HtmlEncode' for this purpose. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/>
Option Strict On
disabling controls by checking off a radio button when the form loads Can't close EXCEL from my VB.NET application Passing a Variable from one web site to another for ASP ContainsFocus equivalent in VB SENDMail Use active directory to scan for software on a remote system? Get Memory Usage of my Program Clearing data from a DataGrid How do i do this in VB .Net |
|||||||||||||||||||||||