How to escape double quote " in thymeleaf? - thymeleaf

I want to put double quotes in a String in Thymeleaf, I have something of the form:
<td th:text='${"Value of \"" + item + "\" is \"" + value + "\"."}'></td>
The result i want is:
<td>Value of "apple" is "1.5".</td>
But I get the following exception:
EL1065E: unexpected escape character.
How can I do this?

I'm not sure it's possible. Something like this works:
th:text='|Value of "${item}" is "${value}".|'
I would personally write it like this:
th:text="${'Value of "' + item + '" is "' + value + '".'}"
I think the reason there is no way to escape double quotes, is that thymeleaf is first parsing as xml/html (which has no escape other than ") and then parsing as thymeleaf second which doesn't really have a chance to get at those strings.

Related

How to add multiple spaces between two strings in ruby .rb file method for pdf generation?

I want to have more spaces between two strings in my rails pdf file.I tried adding more spaces like " " but it is assuming to have a single space.And also, I am not able to use "\n" for my pdf file. The "\n" is not working for pdf generation.
Give a quick solution for it.
Eg:
self.details.map{|i|text = i.name + " " + dob + "\n"}
which gives the output :
ndev 12/12/2020
dev 12/12/2020
Use the constant Prawn::Text::NBSP instead of plain spaces, i.e.
self.details.map {|i| text = i.name + (Prawn::Text::NBSP * 4) + i.dob + "\n" }
The constant contains the Unicode symbol for a non-breaking space and Prawn knows how to correctly handle this for AFM and TTF/OTF fonts.

how to remove backslash from the value of an array

I have following type of arrays
["def, \" \""]
["abc,\" \",def"]
How can i check if there's a \ in value and convert them correctly as follows?
["def", " "]
["abc", " ", "def"]
I have been trying to correct them using
join(',')
delete('\"') split(', ')
but no luck
When you write:
input = "{ \"foo\": \"bar\", \"num\": 3}"
The actual string stored in input is:
{ "foo": "bar", "num": 3}
The escape \" here is interpreted by Ruby parser, so that it can distinguish between the boundary of a string (the left most and the right most "), and a normal character " in a string (the escaped ones).
String#delete deletes a character set specified the first parameter, rather than a pattern. All characters that is in the first parameter will be removed. So by writing
input.delete('\\"')
You got a string with all \ and " removed from input, rather than a string with all \" sequence removed from input. This is wrong for your case. It may cause unexpected behavior some time later.

Remove "\" when we add as a value to dictionary

I have to add value for a key in a dictionary the value is JSON string but it should not have "\" or "\n" in the value,
I tried to remove them and created a string to set the value for key in dictionary but when i add the value to key it automatically adds "\" but when i check the string "\" are not there.
Please let me know if anyone has faced this issue
Value(Json String): Need to set for "CartProducts" Key in the dictionary
[{"type":"radio","product_option_value_id":"633","value":"Medium(40c)","option_value_id":"49","product_option_id":"49","option_id":"56","name":"Medium(40c)"}]
dictionary {
account = guest;
CartProducts = "[{\"product_id\":\"56\",\"option\":\"[{\"type\":\"radio\",\"product_option_value_id\":\"633\",\"value\":\"Medium(40c)\",\"option_value_id\":\"49\",\"product_option_id\":\"49\",\"option_id\":\"56\",\"name\":\"Medium(40c)\"}]\",\"quantity\":\"1\",\"category\":\"Cappuccino\",\"price\":\"3.90\",\"model\":\"Coffee\",\"delivery_date\":\"2016-04-2006:00:01+0000\",\"total\":\"3.90\",\"name\":\"Cappuccino\"}]";
}
Need to remove "\" from the key "CartProducts" in the dictionary "dictionary"
\" in this case is an escape character. It is used to distinguish quotes within quotes.
Take an example:
Product = "my example variable = "hello""
the quotes in this case clashes. To the compiler it looks like
Product = "my example variable = "
//Ouside quotes
hello
//empty quotes at the end
""
Basically it is a mess. So the work around is to use \" which is treated as a single character but is considered part of the string as ".
Other example of escape characters:
\' single quote '
\n new line
\t tab
\\ backslash \

Classic ASP, VBScript Concatenation issue,

Below is some Classic Asp VB Script that i am trying to alter so i can get it to run on my windows 2012 server. (I know its old don't ask :( ). This worked on our old 2003 box but the library it use to use is not supported in 2012. I am now using a stored procedure to send out this e-mail. The problem i am facing is that when i concatenate the sMailBody string i must have some ' or " syntax that is not allowing it to concatenate. When I Response.Write(strRSs) I get the string but all of the HTML renders.
EXEC [dbo].[MailPackage] 'test#test.com', 'tteesstt#ttessttt.com', 'tset' {visible HTML}
for x = 0 to uBound(aRecipientID)
'-- Plugin real content
sMailBody = Replace(sMailBody,"{*~BACKGROUND~*}","'"Session("LiveURL")&"")
sMailBody = Replace(sMailBody,"{*~HEADER~*}",Session("LiveURL")&"images/testing.jpg")
sMailBody = Replace(sMailBody,"{*~BODY~*}",sBody)
sMailBody = Replace(sMailBody,"{*~URL~*}",Session("LiveURL") & "/viewpackage.asp?p=" & sPackageKey & "&u=" & aRecipientID(x) & "&s=" & nSendID&"'")
Dim strRS
strRS = "EXEC [dbo].[MailPackage] " + "'" + aRecipientEmail(x) + "', '" + Session("FromAddress") + "', '" + sSubject + "', '" + sMailBody + "'"
Response.Write(sMailBody)
Response.Write(strRS)
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open Session("ConnectionString")
Conn.Execute strRS
How can i correct my syntax so i can pass sMailBody as my message body into my stored procedure.
Assuming you want to replace the placeholder {*~BACKGROUND~*} in sMailBody with the content of Session("LiveURL"):
change
sMailBody = Replace(sMailBody,"{*~BACKGROUND~*}","'"Session("LiveURL")&"")
to
sMailBody = Replace(sMailBody, "{*~BACKGROUND~*}", Session("LiveURL"))
Basic rules:
Replace need 3 string parameters
A double quote in a string literal must be escaped by ""
VBScript does not interpolate/splice in variable content into string literals
concatenating the empty string - & "" - is a waste of time
The other Replace lines compile, but isn't there a Next missing?
Update thanks to #Lankymart's comment:
... Assuming you want to replace the placeholder {*~BACKGROUND~*} in sMailBody with the single-quoted content of Session("LiveURL") ...
The error in the original code and my probably wrong interpretation of jackncode's intention shows that building strings by concatenation adds so much noise to the expression that it gets messed up easily. See the millions of questions wrt putting quoted pathes and other parameters into command lines for .Run or .Exec.
For such cases it pays to write functions that do the 'embracing' so that you DRY the tangle of funny letters:
>> Function q(s) : q = "'" & s & "'" : End Function
>> Function qq(s) : qq = """" & s & """" : End Function
>> s = "x"
>> t = "<tag attr=#>"
>> WScript.Echo Replace(t, "#", q(s))
>> WScript.Echo Replace(t, "#", qq(s))
>>
<tag attr='x'>
<tag attr="x">
(cf. here)

PHP convert_uudecode function - special characters problem

I'd like to use convert_uudecode function, but encoded string contains a quotation mark ( " ) and also an apostrophe ( ' )
I can't just do it like this:
print convert_uudecode("M:'1T<#HO+V1N87=R;W0N;F%Z=V$N<&PO;&EC96YC97,O8F5S="UD96%L'0` ` ");
cos as you can see there is already a quotation mark.
I also cant do it this way:
print convert_uudecode('M:'1T<#HO+V1N87=R;W0N;F%Z=V$N<&PO;&EC96YC97,O8F5S="UD96%L'0` ` ');
becouse rendered string also contains an apostrophe.
Any help?
Regards,
David
Exchange each Apostrophe ' inside the string with &apos;
and for each Quotation mark " you need to use "
An another alternative is to replace the " with \" and ' with \'
Visit this link below:
Hexadecimal value, Entity encoding etc
http://msdn.microsoft.com/en-us/library/aa226544%28v=sql.80%29.aspx

Resources