Herfried,
| 'StringBuilder.Replace' /returns/ a reference to a string builder which
| contains the final data:
Correct!
However! it also modifies the StringBuilder itself, and then returns a
reference to "Me".
Making the assignment:
| strFileContentsHtml = strFileContentsHtml.Replace(...)
unnecessary with StringBuilder as it is returning "Me", which has already
been modified. Unlike String.Replace that returns a new string.
The StringBuilder returns a reference to allow:
strFileContentsHTML.Replace(vbLf, "<br>").Replace(vbCrLf,
"<br>").Replace(vbCr, "<br>")
More commonly I've seen:
strFileContentsHTML.Append("Hello
").Append(firstName).Append(ControlChars.NewLine)
Which allows each "line" to be on a single source line, however I find it
more confusing then simply using a With statement or the original code.
Which enables C# to use:
strFileContentsHTML.Append("Hello ")
.Append(firstName)
.Append(ControlChars.NewLine);
Which VB.NET does not allow
strFileContentsHTML.Append("Hello ") _
.Append(firstName) _
.Append(ControlChars.NewLine)
However VB.NET has the With statement to cover the above, which IMHO is
better as it doesn't require the type's methods to return the "Me/this"
reference...
Hope this helps
Jay
| > I'm trying to run this code :
| >
| > strFileContentsHTML.Replace(vbLf, "<br>")
| > strFileContentsHTML.Replace(vbCrLf, "<br>")
| > strFileContentsHTML.Replace(vbCr, "<br>")
| >
| > It doesn't replace newline characters with <br>.
|
| 'StringBuilder.Replace' /returns/ a reference to a string builder which
| contains the final data:
|
| \\\
| strFileContentsHtml = strFileContentsHtml.Replace(...)
| ///
|
| --
| M S Herfried K. Wagner
| M V P <URL:
http://dotnet.mvps.org/>
| V B <URL:
http://classicvb.org/petition/>
|