This question already has an answer here:
T-SQL escape quote character
(1 answer)
Closed 8 years ago.
WHERE Variable = 'Lowe's';
But string is ending at Lowe because it recognizes the 's as end of String.
How to circumvent this?
Use two '
WHERE Variable = 'Lowe''s'
SQLFiddle demo
Although escaping ' with '' works, in case you are running this command from any application you should take a look at databinding and using SqlParameters - spares you a lot of headache, improves performance and security.
Related
This question already has an answer here:
How to allow special characters in JSON_VALUE
(1 answer)
Closed 11 months ago.
I'm working with JSON values in a database for the first time. I want to use JSON_VALUE or JSON_QUERY to return a value or section of the JSON, but whoever designed this went and used '-' in the keys, which is an illegal value. Research suggests I need to use FOR JSON to escape it, but I can't figure out how.
Attempt at the query:
select
xt.ID,
JSON_QUERY(xt.JSON_DB_VALUE, '$.CusomterQuery.Details.cust-names') as JSON_WITH_NAMES,
JSON_VALUE(xt.JSON_DB_VALUE, '$.CusomterQuery.Details.cust-names.first-name') as FIRST_NAME
from EXAMPLE_TABLE xt
Error received:
JSON path is not properly formatted. Unexpected character '-' is found at position xx.
Thanks
thanks to Zhorov's quick comment, this is the very simple solution - add quotation marks around the parts of the path with the illegal character.
select
xt.ID,
JSON_QUERY(xt.JSON_DB_VALUE, '$.CusomterQuery.Details."cust-names"') as JSON_WITH_NAMES,
JSON_VALUE(xt.JSON_DB_VALUE, '$.CusomterQuery.Details."cust-names"."first-name"') as FIRST_NAME
from EXAMPLE_TABLE xt
This question already has answers here:
What's the regular expression that matches a square bracket?
(10 answers)
Closed 3 years ago.
Trying to search bbcode-style tags with regular expression:
For example, I needed [user=1]John Dow[/user] with regular: [[user=[0-9]+].*?[/user]]
But couldn't receive needed result.
Remove the outer pair of brackets and escape the literal brackets (unlike the range-of-characters brackets)
let pattern = "\\[user=[0-9]+\\].*?\\[/user\\]"
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to escape double quotes in string?
I need to print a "abc" inside #""
My current string is
[displayLbl setText:#"press stop"];
But i need:
[displayLbl setText:#"press "stop""];
How can i do this?
[displayLbl setText:#"press \"stop\""];
Roland Keesom's answer is of course correct. But you might also consider to use typographic quotation marks, which usually look better:
[displayLbl setText:#"press “stop”"];
(You only have to find them on the keyboard (-: )
This question already has answers here:
How to uppercase the first character of each word using a regex in VB.NET?
(9 answers)
Closed 8 years ago.
I'm looking for do this in VB.NET,
hy how are you
to,
Hy How Are You
Anyone have any idea?
This following will do what you want without using regex (and is more readable than a regex solution):
Dim s As String = "some sentence that i want to capitalise"
Debug.WriteLine(Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(s))
Output:
Some Sentence That I Want To Capitalise
And you can also do this (from the Microsoft.VisualBasic Namespace):
Debug.WriteLine(StrConv(s, VbStrConv.ProperCase))
You can do that using regular expressions. There are a useful class named Regex that will help you a lot. Please follow this link for more information.
I have a string like "Hello'World" and a DataTable with some records in it. One of those records is "Hello'World".
The problem is, when I do a .Select in the DataTable, it only tries to search for the "Hello" part and throws an error on "World" because it interprets the ' (single quote) like the closing quote on sql.
DataTable.Select("text = 'Hello'World'")
I have gone through msdn doc, and it says I can escape some characters with [] brackets or f.slashes \, but I just can't figure out: .select("text = 'Hello[']world'")
I've done some reading: Verbatim in vb - c# and "jmcilhinney" explains it really well. BUT, it did not answer my question for what I want to do. In stackoverflow.com, a same question is posted but in c#, but I can't find a way to use # in vb.
Can you please redirect me to more doc, examples or any one of you have ever encountered this problem?
Use '' (this is 2 ' characters).
DataTable.select("text = 'Hello''World'")