Declare HTML tag as a string in VB.NET - vb.net

I'm trying to assign the following HTML as a value to variable type string
'here's the tag
'$("#close").click(function(){$.notifyBar({ html: "Click 'close' to hide notify bar", close: true, delay: 1000000 });});
Dim htmltag = "$("#close").click(function(){$.notifyBar({ html: "Click 'close' to hide notify bar", close: true, delay: 1000000 });});"
I got a lot error message about the quotation in the string.

You need to use escape characters on the quotations otherwise they break the variable input. The VB.net escape for quotations is double quote:
Dim htmltag = "$(""#close"").click(function(){$.notifyBar({ html: ""Click 'close' to hide notify bar"", close: true, delay: 1000000 });});"
In your example, the compiler would see the string as:
Dim htmltag = "$("
With lots of unknown stuff after it!
Other languages have different escape characters, javascript for example is backslash.

Related

KaTeX does not render math between dollars sign on not the same line

I want to create an editor with ace + katex. Problem is that double dollars sign does not compiles correctly
For example:
Good
$$\mathcal D = 25+4\cdot6\cdot1=49=7^2$$
Bad
$$
\mathcal D = 25+4\cdot6\cdot1=49=7^2
$$
Katex render options:
renderMathInElement(this.katexView, { delimiters: [
{left: "$$", right: "$$", display: true},
{left: "$", right: "$", display: false},
]});
Found my mistake, I inserted text for katex node via innerText, but katex need innerHTML
Why not use directly the equation / align environments?
\begin{equation}
\mathcal D = 25+4\cdot6\cdot1=49=7^2
\end{equation}
Or simply
\[
\mathcal D = 25+4\cdot6\cdot1=49=7^2
\]

VueJS and UTF-8 encoding issue: Correctly formatting user copy and pasted text

I am using a data api that is returning text like so (from an archaic database):
I’m attaching a couple of our “quick look� cards covering the process
Notice the ’ symbols in the text. It appears that perhaps the user had copy and pasted text from an email message (outlook) or Microsoft Word and it appears to be a replacement for a comma or apostrophe (or who knows what else)?
Looks like this is what needs to be replaced:
[{broken: '–', fixed: "—"}
{broken: "—", fixed: "–"}
{broken: "‘", fixed: "‘"}
{broken: "’", fixed: "’"}
{broken: "“", fixed: "“"}
{broken: "â€", fixed: "”"}, ...]
Is there something I can do on the front end to replace those symbols with the correct character?
This sounds like an encoding problem and is described here and is, as you also described, reduced to a few characters:
The following characters fail, while other characters display
correctly:
€ ‚ ƒ „ … † ‡ ˆ ‰ Š ‹ Œ Ž ‘ ’ “ ” • – — ˜ ™ š › œ ž Ÿ.
There is also a debug sheet to find out the expected characters in UTF-8.
So maybe a solution would be to replace these list of characters after getting the data from the API or handling it with a function.
I made a fiddle with replaces that chars with the function replaceEncodingErrorCharsInString() :
new Vue({
el: "#app",
data: {
encodingReplacement: [
{
broken: '–',
fixed: "—"
},
{
broken: "—",
fixed: "–"
}, {
broken: "‘",
fixed: "‘"
}, {
broken: "’",
fixed: "’"
}, {
broken: "“",
fixed: "“"
}, {
broken: "â€",
fixed: "”"
}],
exampleTexts: [
"This is – !",
"This is — !",
"This is ‘ !",
"This is ’ !",
"This is “ !",
"This is – !"
]
},
methods: {
replaceEncodingErrorCharsInString: function(text){
for(let i=0; i < this.encodingReplacement.length; i++) {
// string contains "broken" chars
if(text.includes(this.encodingReplacement[i].broken)) {
text = text.replace(this.encodingReplacement[i].broken, this.encodingReplacement[i].fixed)
}
}
// string is fine, just return it
return text
}
}
})

Change linebreaks between XML elements while writing XML document

I'm using Xmlwriter method to write an html document. When adding elements, it automatically inserts crlf linebreaks between them, no problem there.
Except at some point, when I want to add some tags in my inner text: what I get is a crlf after each , which is definitely not desirable.
I can live without linebreaks between elements, but I can't find the setting in the xmlwriter that could give me this... As far as I can tell, .NewLineHandling only deals with linebreaks in text, not those inserted automatically between elements.
Here are my settings:
With ReportSet 'XML/HTML file writing settings
.Encoding = Text.Encoding.UTF8
.Indent = True
.IndentChars = vbTab
.OmitXmlDeclaration = True
.NewLineHandling = Xml.NewLineHandling.None
End With
And here is the spot where I definitely don't want any linebreak between elements:
For Each section As DiffLib.DiffSection In test
If section.IsMatch Then
cp = EltCnt(k).Substring(n, section.LengthInCollection1)
Report.WriteString(cp)
Else
rmv = EltCnt(k).Substring(n, section.LengthInCollection1)
add = EltCntR(k).Substring(o, section.LengthInCollection2)
With Report
.WriteStartElement("SPAN")
.WriteAttributeString("style", "background-color: #ffcccc; text-decoration: line-through;")
.WriteString(rmv)
.WriteEndElement()
.WriteStartElement("SPAN")
.WriteAttributeString("style", "background-color: #ccffcc;")
.WriteString(add)
.WriteEndElement()
End With
End If
n += section.LengthInCollection1
o += section.LengthInCollection2
Next
So: what should I do not to have linebreaks between the tags?
Never mind, browsers are smarter than me, and just ignore those pesky linebreaks... No need to remove them.

Get text between quotes in WebBrowser or HttpWebRequest? VB.NET

I have an API, the API returns the input like this:
{"phrase":"decrypted","parsed":"encryptedcode","response":"done","code":6}
Everything around "decrypted" and "encryptedcode" stays the same.
I need to get the "decrypted" part only. No idea where to even begin.
I'm using WebBrowser, since I'm not any good at HttpWebRequest, so if you could answer as WebBrowser code instead of HttpWebRequest, I would appreciate it.
Answer
clean = WebBrowser1.Document.Body.InnerText.Replace("phrase", "").Replace(":", "").Replace("parsed", "").Replace(md5, "").Replace("code", "").Replace("The MD5 hash was cracked.", "").Replace("""", "").Replace("6", "").Replace("}", "").Replace("{", "").Replace(",", "").Replace("response", "")
so I could do
listbox.items.add(clean)
and it wouldn't look messy.
Just Replace : to ,
Then you input looks like
{"phrase", "decrypted", "parsed", "encryptedcode", "response", "done", "code", 6}
then do as below
Dim str() As String = {"phrase", "decrypted", "parsed", "encryptedcode", "response", "done", "code", 6}
Dim decrypted As String = str(1)
you get Decrypted part

deserialization issue with char '\'

Does json.net have an in built method that would escape special characters? My json strings I recv from vendors have \, double " .
If not what is the best way to escape the special charecters before invoking JsonConvert.DeserializeObject(myjsonString)?
My sample json string
{
"EmailAddresses": [
{
"EmailAddress": "N\A"
}
]
}
Pasting this in json lint results in
Parse error on line 4:
... "EmailAddress": "N\A",
-----------------------^
Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '['
VB.NET code
instanceofmytype = JsonConvert.DeserializeObject(Of myType)(myJsonString)
Exception: Newtonsoft.Json.JsonReaderException: Bad JSON escape sequence:
The JSON is not valid: a \ must be followed by one of the following: "\/bfnrtu. Since it's followed by A, Json.NET chokes (as it ought to). The source of your JSON should be fixed. If this is not an option, you can make a guess to fix it yourself, e.g.
myStr = Regex.Replace(myStr, "\\(?=[^""\\/bfnrtu])", "\\")
You shouldn't have to worry about it. JSON.NET handles a lot of nice things for you. It should just work.
Have you tried it?