Back-Tick and Single Quote in ABAP - syntax

If I wanted to store the following string literal in a variable :
ab'c'd
Then what are the various ways to do it, using a single quote (') and/or a back-tick (`) ?

You have two choices:
Single Quotes:
var = 'ab''c''d'.
Back Tick:
var = `ab'c'd`.
Using the Back Tick is the simpler solution, assuming you're only concerned about single quotes.

Quotes should be usually "quoted" with backticks.

Related

how to check if a string contains any form of an apostrophe not just single quote and ruby

I am using the following code to check if a string contains an apostrophe:
string.scan(/’|'/)
I have included two types of single quotation because I found that using just the standard ' did not catch some strings that contain an apostrophe using the ’
My concern is that if I am checking strings that may contain other fonts or styles my regex won't catch the apostrophe.
Is there a more general approach that would catch all forms of an apostrophe?
Straight single quote is the generic ver­ti­cal quo­ta­tion marks:
straight sin­gle quote (')
Curly quotes are the quo­ta­tion marks used in good ty­pog­ra­phy. There are two curly single quote char­ac­ters:
the open­ing sin­gle quote (‘)
the clos­ing sin­gle quote (’)
Going by the above three variants:
You maytry this:
string.scan(/['‘’]/)
Those would probably be the most common ones :
/[‘’']/
If you just need to check if a string contains a regex, you shouldn't use scan :
"apostrophe's" =~ /[‘’']/ #=> 10
=~ will stop at the first match.

Escape characters in teradata jdbc connection string

I have a teradata database name that contains a dash character -.
Searched the web but in vain. Does somebody know how can you escape the special characters in jdbc connection string? The string looks as follows:
jdbc:teradata://HostName/DATABASE=Database-Name
When I create a connection with this url I get syntax error. Also tried to put database parameter in single or double quotes, and to surround the special charachers with { }.
Thanks for help!
Finally found the answer here: https://jira.talendforge.org/browse/TDI-18863. The correct way is to enclose both parameter name and value in single quotes:
jdbc:teradata://HostName/'DATABASE=Database-Name'
Update: No, this does not work, see comment below.
Answering my own question:
My problem was that I didn't realise that my database name had some trailing whitespaces in the end.
TeraDriver uses single quotes to escape spaces and commas. This means that the database name should be in single quotes. If there are no single quotes, spaces and commas are considered to be the end of parameter value. If there are single quotes in database name, they should be presented as two single quote characters.
'Database-Name '
Whatever is within single quotes will be used with sql query: "database Database-Name". To escape '-' we need double quotes. So both single and double quotes in correct order should be used:
"jdbc:teradata://HostName/DATABASE='\"Database-Name\"'"
Have you tried a \ character which is supposed to be an escape character in Java?
jdbc:teradata://HostName/DATABASE=Database\-Name

What's the point of escaping a single backslash in single quotes in Ruby?

I don't quite understand what's the point of escaping a single backslash when you have a string in single quotes in Ruby. Why does Ruby treats backslashes 'differently'?
backslashes are an escape character so if you were to write '\' would think you were trying to escape the '.
Otherwise if it treated single character strings differentls you wanted to write ' you would have to use double quotes, which will quickly get harder to maintain when you need to remember which quotes to use when.
If your question is actually "What is the point of the language design requiring us to escape a backslash in single (as opposed to double) quotes", then that is to allow single quotes to appear within a string literal written with single quotes. In order to do that, there must be an escape character for single quotes, which is the backslash, and then, the escape character itself needs to be escaped.

Interpolation within single quotes

How can I perform interpolation within single quotes?
I tried something like this but there are two problems.
string = 'text contains "#{search.query}"'
It doesn't work
I need the final string to have the dynamic content wrapped in double quotes like so:
'text contains "candy"'
Probably seems strange but the gem that I'm working with requires this.
You can use %{text contains "#{search.query}"} if you don't want to escape the double quotes "text contains \"#{search.query}\"".
'Hi, %{professor}, You have been invited for %{booking_type}. You may accept, reject or keep discussing more about this offer' % {professor: 'Mr. Ashaan', booking_type: 'Dinner'}
Use
%q(text contains "#{search.query}")
which means start the string with single quote. Or if you want to start with double quote use:
%Q(text contains '#{text}')

Which style of Ruby string quoting do you favour?

Which style of Ruby string quoting do you favour? Up until now I've always used 'single quotes' unless the string contains certain escape sequences or interpolation, in which case I obviously have to use "double quotes".
However, is there really any reason not to just use double quoted strings everywhere?
Don't use double quotes if you have to escape them. And don't fall in "single vs double quotes" trap. Ruby has excellent support for arbitrary delimiters for string literals:
Mirror of Site - https://web.archive.org/web/20160310224440/http://rors.org/2008/10/26/dont-escape-in-strings
Original Site -
http://rors.org/2008/10/26/dont-escape-in-strings
I always use single quotes unless I need interpolation.
Why? It looks nicer. When you have a ton of stuff on the screen, lots of single quotes give you less "visual clutter" than lots of double quotes.
I'd like to note that this isn't something I deliberately decided to do, just something that I've 'evolved' over time in trying to achieve nicer looking code.
Occasionally I'll use %q or %Q if I need in-line quotes. I've only ever used heredocs maybe once or twice.
Like many programmers, I try to be as specific as is practical. This means that I try to make the compiler do as little work as possible by having my code as simple as possible. So for strings, I use the simplest method that suffices for my needs for that string.
<<END
For strings containing multiple newlines,
particularly when the string is going to
be output to the screen (and thus formatting
matters), I use heredocs.
END
%q[Because I strongly dislike backslash quoting when unnecessary, I use %Q or %q
for strings containing ' or " characters (usually with square braces, because they
happen to be the easiest to type and least likely to appear in the text inside).]
"For strings needing interpretation, I use %s."%['double quotes']
'For the most common case, needing none of the above, I use single quotes.'
My first simple test of the quality of syntax highlighting provided by a program is to see how well it handles all methods of quoting.
I use single quotes unless I need interpolation. The argument about it being troublesome to change later when you need interpolation swings in the other direction, too: You have to change from double to single when you found that there was a # or a \ in your string that caused an escape you didn't intend.
The advantage of defaulting to single quotes is that, in a codebase which adopts this convention, the quote type acts as a visual cue as to whether to expect interpolated expressions or not. This is even more pronounced when your editor or IDE highlights the two string types differently.
I use %{.....} syntax for multi-line strings.
I usually use double quotes unless I specifically need to disable escaping/interpolation.
I see arguments for both:
For using mostly double quotes:
The github ruby style guideline advocates always using double quotes:
It's easier to search for a string foobar by searching for "foobar" if you were consistent with quoting. However, I'm not. So I search for ['"]foobar['"] turning on regexps.
For using some combination of single double quotes:
Know if you need to look for string interpolation.
Might be slightly faster (although so slight it wasn't enough to affect the github style guide).
I used to use single quotes until I knew I needed interpolation. Then I found that I was wasting a lot of time when I'd go back and have to change some single-quotes to double-quotes. Performance testing showed no measurable speed impact of using double-quotes, so I advocate always using double-quotes.
The only exception is when using sub/gsub with back-references in the replacement string. Then you should use single quotes, since it's simpler.
mystring.gsub( /(fo+)bar/, '\1baz' )
mystring.gsub( /(fo+)bar/, "\\1baz" )
I use single quotes unless I need interpolation, or the string contains single quotes.
However, I just learned the arbitrary delimiter trick from Dejan's answer, and I think it's great. =)
Single quote preserve the characters inside them. But double quotes evaluate and parse them. See the following example:
"Welcome #{#user.name} to App!"
Results:
Welcome Bhojendra to App!
But,
'Welcome #{#user.name} to App!'
Results:
Welcome #{#user.name} to App!

Resources