Classic ASP, VBScript Concatenation issue, - stored-procedures

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)

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 escape double quote " in 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.

How to replace double quotes in Erlang

This is probably a rather trivial question for the Erlang experts - I'm trying to have my ejabberd server store offline messages (in a Riak db) which inherently do contain double quotes (") around various values, etc. I get a format error when I try to create a Riak database object from them, and testing of replacing the double quotes with an escape character (\") corrects the issue. The question is how can I do this replacement manually?
I tried the following code but somehow doesn't work.
(ejabberd#xxx-xx-xx-xxx)4> re:replace(""hello"", """, "\"", [{return, list}, global]).
* 1: syntax error before: hello
So essentially I'm trying to replace the embedded " around the hello word with \".
I don't know Erlang, but you probably need something like this:
"\"hello\"", "\"", "\\\""
You must escape both " and \ in replacement string.
The Erlang literal syntax for strings uses the "\" (backslash)
character as an escape code. You need to escape backslashes in literal
strings, both in your code and in the shell, with an additional
backslash, i.e.: "\".
Example:
Let's make an example. I use $ Erlang symbol which will be substituted with ascii integer of a character to show what is happening behind each string which basically is a list of integer.
Subject = [$"] ++ "hello" ++ [$"] = "\"hello\"".
Target = [$"] = "\"".
Replacement = [$\\, $\\, $"] = "\\\\\"".
Result = re:replace(Subject, Target, Replacement, [{return, list}, global]).
Now with getting the length of Subject and Result we can find the difference:
7 = length(Subject). %% => 7 characters: " h e l l o "
9 = length(Result). %% => 9 characters: \ " h e l l o \ "

Dispaly special characters ("#") in uitextview content

I have to display "#" in the UITextview content and after to put some information.
I looked on the internet via google but I didn't find an explanation which make
me understand the good approach.
Can you help me with some extra advice ?
Thanks !
You can simply do it like this:
_textView.text=#"#Hi Hello"; result will be #Hi Hello
However if you want to use " in the text you need to append it to backslash \
_textView.text=#"#Hi \"Hello"; result will be #Hi "Hello
You can enter almost all special characters without any problem, but you need to take care for the double quotes:
_textView.text=#"#Hi \"Hello * ! # # $ % ^ & ( ) _ + - [ ] ; ' {} <> ,. / ? : \" ";

Excel parse cell value

I have placed the following in cell A1:
"a lot of text marker: xxx some more text"
I would like to copy the xxx value into cell A2.
Any suggestions on how this could be done?
Thanks
=MID(A1, FIND("marker:",A1) + LEN("marker:"), 4)
I am assuming that the xxx (per your example) is 3 characters long and a space is present between "marker:" and "xxx".
Just my two cents. Find() is case sensitive so if the text in A1 is
"a lot of text Marker: xxx some more text"
Then Find will give you an error.
You can use Search() in lieu of FIND()
=MID(A1, SEARCH("marker: ",A1) + LEN("marker: "), 3)
Also depending upon your regional settings you might have to use ";" instead of ","
If you wanted a VBA solution, this worked for me using your sample input:
Function GetValue(rng As Excel.Range) As String
Dim tempValue As String
Dim arrValues() As String
' get value from source range
tempValue = rng.value
' split by ":" character
arrValues = Split(tempValue, ":")
' split by spaces and take the second array element
' because there is a space between ":" and "xxx"
GetXXXValue = Trim$(Split(arrValues(1), " ")(1))
End Function
To use, put this code into the sheet module (see Where do I paste the code that I want to use in my workbook for placement assistance) and then put the following into cell A2:
=GetValue(A1)

Resources