Cleaning up a string
I have the following string which I need to get onto one line for database storage and retrieval purposes:
{"id":8,"heading":"heading goes here","content":"<p>
content goes here</p>
"}
I am using the following command to get this onto one line:
Dim strContent As String = Request.Form("strContent").Replace(vbCr, "").Replace(vbLf, "")
This puts the above string onto one line as 开发者_如何学编程follows:
{"id":8,"heading":"heading goes here","content":"<p> content goes here</p>"}
However, within the string there seems to be a "tab" character
How do I get rid of that?
Request.Form("strContent").Replace(vbCr, "").Replace(vbLf, "").Replace(vbTab, "")
In fact I imagine you could use vbCrlf
instead of the two replaces ie
Request.Form("strContent").Replace(vbCrlf, "").Replace(vbTab, "")
Although I would say that I think removing characters this way and then hoping to reinstate the original HTML could be fraught with problems. But maybe not. Depends on your particular issue.
If you are wanting to preserve these control characters and pass them to the client you could try something along the lines of
Request.Form("strContent").Replace(vbCrlf, "%0d%0a").Replace(vbTab, "%09")
This will make the chars safe for transmission with JSON.
You can use vbTab
in the same way you used vbCr
- there is also a vbCrLf
:
Request.Form("strContent").Replace(vbCrLf, "").Replace(vbTab, "")
However, the database should be able to store text that includes a line and tabs - unless there is a specific requirement to clean the string up, you shouldn't.
By the way - this string is not HTML.
精彩评论