Escaping Double Quotes in Velocity - velocity

I have a string which i am getting
#set($locator=$dataElement.getLocator().get(0))
#set($selector = $locator.getSelector())
$selector is string type and it contains double quotes as well
when i am calling
executor.click(new Params("$selector",BY.$By));
selector have double quotes, which needs to be replaced with single quotes.
i tried with replacing but it is giving error
i referred question
Escaping quotes in velocity template
But this also don't solved my purpose
example
$selector can be something like
a[#href="somelink"]
and i want that to changed to
a[#href='someLink']

For velocity
$selector.replaceAll('"',"'")
replaces " with '
so something like:
executor.click(new Params("$selector.replaceAll('"',"'")",BY.$By));
this works fine

Related

element in a array contains double quotation

I would like to have ""apple"" as the element in the array as the output. The sad thing is it has to be in this kind of format.
But presto automatically added the escape character "/". (i.e "/"apple/"")
How do I get rid of it
Simply use two double quotes around the string apple ""apple""

Replace special qoutes with normal

In VB.NET how do I replace special opening and closing double quotes (“ and ”) with ASCII quotes (").
Ive tried
s = s.replace("“", """")
but it seems that Visual Studio consider the “ quote in my code to be a normal quote leaving me with an invalid statement.
Unfortunately VB.NET doesn't support escape sequences but you can use ChrW() to specify code point:
s = s.Replace(ChrW(&H201C), """")
That's for “, code for ” is &H201D. Note that using code points you're free to search & replace any Unicode character (not just what VB.NET has an escape for - like ").
For complete list see: http://unicode-table.com/en/
If you want to use a quotation mark inside a string, VB doesn’t know whether the quotation mark is supposed to end the string or not. In C#, this would be fixed by escaping the quotation mark, i.e. in place of """ you’d write "\"". In VB, the same is done by doubling the quotation mark, i.e. """".
Back to your curly quote. The same as for straight quotes applies according to the VB language specification (¶1.6.4). So to write a curly quote in code, try the following:
s = Replace(s , "““", "“")
a second way: s = Replace(s , ChrW(&H201C), "“")

What is the difference between double and single quotes in pig?

I always thought that '' and "" were the same in pig, but today I got the
Unexpected character '"'
error on
register datafu-pig-1.2.1.jar
define Coalesce datafu.pig.util.Coalesce;
...
Coalesce(x,"a")
while
Coalesce(x,'a')
works just fine.
So, what is the difference between single and double quotes?
Pig doesn't support double quotes for string literals(ie chararray). All the chararray must be enclosed within single quotes.
A String or Chararrays are represented in interfaces by java.lang.String.
Constant chararrays are expressed as string literals with single quotes, for example, 'fred'
Reference:http://chimera.labs.oreilly.com/books/1234000001811/ch04.html#scalar_types

Update Using Double Quotes

I have issue in running the following sql:
update personal_view test set session_state="<script type="text/javascript">
alert (mstrApp.sessionState);
</script>"
I know it is because of the double quotes within the double quotes and symbols like ; / < and > in the sql.
Any idea on how to fix this issue?
Try:-
update personal_view test set session_state='"<script type="text/javascript">'
In most SQL dialects strings are wrapped in single quotes double quotes have no special meaning inside a string.

Remove double quote only when inside another double quote (VB.NET)

I'm using the library JSON.NET to bring a JSON string from the web, but the problem is that I get a double quote within a string.
the string that comes from the web is as follows
{"accionObjeto":"post","accionTipo":"comentario","ts":"02:48:55","nick":"seba123neo","userId":"1180918","id":15521634,"accion_name":"Hola","url":"","titulo":"Hola como" estas"}
the string is perfect except the end
here is the problem
"titulo":"Hola como" estas"
I have to remove that double quote, because otherwise the JSON is "invalid"
I've looked everywhere but can not find how to do this, I need only to erase the double quote, but not erase all other quotes in the entire string.
Thanks for your help.
It is not clear from your question whether you are generating the JSON string or if you are downloading it from the web. If you are creating it and the library is not escaping strings correctly, consider escaping them yourself.
This is a list of valid escapes
\b Backspace (ascii code 08)
\f Form feed (ascii code 0C)
\n New line
\r Carriage return
\t Tab
\v Vertical tab
\' Apostrophe or single quote
\" Double quote
\\ Backslash caracter
As you can see you would have to escape a double quote by \". Before you code it yourself, look closer into the library you are using. I would be astonished, if it did not provide such functionality.