BASIC - How to include double quotes in string? - basic

I'm using the BASIC language. Is there any way to include double quotes in a string?
I tried using \" but it doesn't work.
NOTE: I'm using Nano-10 PLC which supports combination of Ladder and BASIC

#vlad awtsu's answer is correct for the normal BASIC language. (+1 for him)
However it didn't work for me on the PLC I've mentioned in the question.
Using CHR$(&H22) did the job for me. (also works on normal BASIC)
Print "Hello "+ CHR$(&H22) +"World"+CHR$(&H22)
It prints:
Hello "World"

try this one
"She said, ""You deserve a treat!"" "
add "" ""

Dushyant Bangal is correct - although CHR$(34) should work equally well. There is no need to put the value into hex unless you have a preference for it.
(Also, whether doubling up the "" works in "normal BASIC" depends what you mean by "normal". I've seen countless dialects in which CHR$ is the only option.)

Related

Add the ability to use tabulation in Nim

Yes, we can convert tabs to spaces via Sublime, VS-Code and etc, it's not a big problem.
But what if I want to get rid off this additional action ?
Found answer by adding this line to .nim file :
#? replace(sub = "\t", by = " ")
My additional question is :
What is this #?, how this thing works and what kind of variations I can find also, for example:
#!
#some_chinese_character
It is called a "source code filter", it's like a Nim preprocessor less powerful than macros and templates. You can read about it here: https://nim-lang.org/docs/filters.html
Anyway, I wouldn't recommend using it, but rather using an editor which replaces tabs with spaces, such as vscode. This seems more like an hack than an actual solution.

using special characters in parameters and variables in batch without external file use

Before you go marking this as a duplicate hear me out
My question;
A: has different requirements than all the others (which are basically "whats an escape character?") Including: not having to use an external file to enter in parameters to functions
B: questions the existence of this mess rather than accepting 'no' or 'its complicated' as the answer
C: understands that there are escape characters that already exist and ways to work around that
D: comes from a different skill level and isn't a 2-7 years old question
E: requires the use of quotes rather than something like [ because quotes are the only thing that works with spaced strings
Also before ya'll say I didn't try stuff
I read these (all of it including comments and such):
Batch character escaping
http://www.robvanderwoude.com/escapechars.php
https://blogs.msdn.microsoft.com/oldnewthing/20091029-00/?p=16213
using batch echo with special characters
Escape angle brackets in a Windows command prompt
Pass, escape and recognize Special Character in Windows Batch File
I didn't understand that all fully, because to fully understand all that I'd have to be much better at batch but here is what I gleaned:
So I understand theres a whole table of escape sequences, that ^ is the most used one, that you can use Delayed Expansion to do this task so that the characters don't get parsed immediately, just 'expanded' at runtime, but then that the Enable Delayed expansion thing doesn't always work because with pipe characters, the other files/things being piped to/from don't inherit the expansion status so
A: you have to enable it there too
B: that forces you to use that expansion
C: it requires multiple escape characters for each parsing pass of the CLI which apparently is hard to determine and ugly to look at.
This all seems rather ridiculous, why wasn't there some sort of creation to set a string of odd inputs to literal rather than process the characters. Why wasn't it just a simple flag upon some super duper special character (think alt character) that would almost never appear unless you set the font to wingdings. Why does each parsing pass of pipe characters remove the escape characters? That just makes everything insane because the user now has to know how many times that string is used. Why hasn't a tool been developed to auto scan through odd inputs and auto escape them? We have a table of the rules, is it really that hard? Has it been done already? What would it require that's 'hard'?
Down the rabbit hole we go
How did I get here you ask? Well it all started when I made a simple trimming function and happened upon one of the biggest problems in batch, escaping characters when receiving inputs. The problem is alot of my inputs to my trimming function had quotes. Quotes are escaped by using "" in place of " so something like
::SETUP
::parenthesis is just to deliniate where it goes, it isn't
::actually in
::the code
set "var=(stuff goes here)"
call :TrimFunc "%var%",var
:TrimFunc
::the + are just to display the spacing otherwise I can't tell
echo beginning param1 is +%~1+
::code goes here for func
gotoEOF
::END SETUP
::NOTE the + characters aren't part of the actual value, just the
::display when I run this function
set "var=""a"""
::got +"a"+
will work but
set "var="a "
::got +"a+
::expected +"a +
set "var="a ""
::got +"a+
::expected +"a "+
set "var="a " "
::got +"a+
::expected +"a " +
set "var="a"
::got +"a",var+
::expected +"a+
will not work as expected. oddly,
set "var="a""
::got +"a"+
seemes to work despite not being escaped fully. Adding any spaces seems to disrupt this edge case.
Oddly enough I've tried doing:
set 'var="a"'
::got ++
::expected +"a"+
But I have no idea what changing ' to " actually does when its the one that contains the argument (not the ones that are supposed to be literal).
To see what would happen and
What I want:
Surely there must be some sort of universal escape character thing such that I can do this (assume the special character was *)
set *var=""something " "" " """*
call :TrimFunc "%var%",var
echo +%~1+
would net me
+""something " "" " """+
with no problems. In fact, why can't I have some universal escape character that can just be used to take in all the other characters inside it literally instead of the command line trying to process them? Perhaps I'm thinking about this wrong but this seems to be a recurring problem with weird inputs all over. I just want my vairbales, pipes and strings and all that to just STAY LITERAL WHEN THEY'RE SUPPOSED TO. I just want a way to have any input and not have any weird output, it should just treat everything literally untill I want it not to because it was enclosed by the mystical super special character that I just invented in my mind.
::noob rant
I don't see why this was never a thing. Whats preventing the makers of this highly useful language from simply creating a flag and some character that is never used to be the supremo escape character. Why do we need like 10 different ways of escaping characters? I should be able to programatically escape inputs if necessary, it should NEVER be the users job to escape their inputs, thats absolutely ridiculous and probably a violation of every good coding standard in existence
::END noob rant
Anyways. I'd be happy to be enlightened as to why the above is or isn't a thing. I just want to be able to use quotes IN A STRING (kinda important) And I can't comprehend why its not as simple as having one giant "treat these things as literals" flag that ALWAYS JUST WORKS(tm).
By the way, In case you're wondering why my function takes in the name of the variable it's writing to, I couldn't figure out how to get labels inside labels working without using delayed expansion. Using that means the variable I'm making is local not global so I use the name of the global variable to basically set it (using it's name) to the local value on return like this:
endlocal & set "%~2=%String%"
Feel free to yell at me on various things because I am 99% certain I'm doing something horribly syntactically wrong, have some bad misunderstandings or am simply way to naive to truly understand the complexity of this problem but to me it seems amazingly superfluous.
Why can't the last quote be used like the special character it is but any preceeding ones are taken literally (maybe depending upon a flag)
for example
set "var="a ""
why doesn't the ending two quotes act specially and the ones in between act literally? Can the CLI not tell where the line ends? Can it not tell the difference between the first and last quotes and the ones in between? This seems simple to implement to me.
As long as I can echo things properly and save their literal value from parameter to variable I'm happy.
Firstly, I'm don't really understand why you will want to use set "var=something" instead of set var=something, it doesn't seems to have difference.
Secondly, hope that helps, which I have (recently? IDK.) invented a method to deal with the annoying quotes. Hope this batch inspires or helps you to do sth similar.
#echo off
title check for length of string
color de
mode con: cols=90 lines=25
goto t
:t
set str=error
set /p str=Please enter four characters:
set len=0
goto sl
:sl
call set this=%%str:~%len%%%
if not "%this%" == "" (set /a len+=1 & rem debug" == "" (set /a len+=1
goto sl)
if not "%len%" == "4" (set n= not) else (set n=)
echo This is%n% a four character string.
pause >nul
exit
Which in your case:
if not "%var%" == "" (call :TrimFunc "%var%",var & rem debug" == "" (call :TrimFunc "%var%,var)
)
Hope that helps. Add oil~ (My computer doesn't support delayexpansion with unknown reason. Therefore, most of the codes are a bit clumsy.)
P.S.: If you are simply removing text and not replacing text, why not use set var=%var:string=%? If the string required is a variable too, then you can try this: call set var=%%var:%string%=%%

Combining formulas that include "" using putexcel

I'm trying to save some time generating a lot of reports on Excel with a program from Stata using the putexcel command.
It has worked perfectly. However, I'm encountering a problem when mixing 3 formulas in which one includes quotation marks to denote a space " ".
To be more specific, this is the code I'm using:
putexcel B2=formula("IF((VLOOKUP(A2;HI!$1:$1048576;2;));" ";VLOOKUPA2;HI!$1:$1048576;2;))") using "`archivo'", modify sheet("DEFGGF")
The problem here is that it works in Excel, but instead of the space enclosed in " " I'm getting a 0 since it doesn't read the quotation marks.
I have tried enclosing the "" in several other ways, like
'""`
or
"'"'`"`"
but they don't work.
I would post this as a comment, but I never am able to get the backtick (`) character to display properly in a comment.
I think your code should look like
putexcel B2=formula(`"IF((VLOOKUP(...));" ";VLOOKUP(...))"') using ...
but I admit to not having tested this solution. But the general principles involved are explained in the output of the Stata command help quotes##double.

Perl string, a variable in a string followed by a single quote and another character does what?

I just encountered my first odd "quirk" of Perl in a long time. I can't seem to find any documentation of it online and I don't know what Perl is doing.
Let's just cut to the chase:
my $name = "Steve";
my $v = "$name's name is $name";
The value of $v would turn out to be " name is Steve". I use vim and the first $name turns an odd color (green instead of the normal teal). So I know this is a known feature, but I don't understand what is happening.
For those who might want to suggest alternatives, I know I can do either of the following without any problems:
$v = $name . "'s name is $name";
$v = "${name}'s name is $name";
I just am curious as to what Perl is doing in the first case I gave and what its uses are.
Quoting perlmod,
The old package delimiter was a single quote, but double colon is now
the preferred delimiter, in part because it's more readable to humans,
and in part because it's more readable to emacs macros. It also makes
C++ programmers feel like they know what's going on--as opposed to
using the single quote as separator, which was there to make Ada
programmers feel like they knew what was going on. Because the
old-fashioned syntax is still supported for backwards compatibility,
if you try to use a string like "This is $owner's house", you'll be
accessing $owner::s; that is, the $s variable in package owner,
which is probably not what you meant. Use braces to disambiguate, as
in "This is ${owner}'s house".
You could also use "This is $owner\'s house".

Could not able to replace \" with " in html tags using C#

I want to replace a as using C#. I could not able to achive this using Regex.Replace functions as follos
Regex.Replace(html, "\\"", "\"");
execution this command again produces the original output
Anyone have already faced issue like this,Any help would be of greatly appreciated.
Regards,
Ganesan
first of all "\\""produces a compiler error, since you are just escaping one backslash but not the quote.
you are working with 2 escape mechanisms here, one is from the c# compiler, and another is from the regex interpreter.
Which means:
when you give this C# string as a regex: "\\\"" then after compilation there is a string looking like that \", which is then interpreted by the regex engine, which also uses \ as the escape character. therefor regex will escape ", so your code will replace " with "
so if you now use "\\\\\"", first the c# compiler will make \\" out of that, then the regex engine will make \" out of that (both are using \ as escape character)
now c# has a nice little feature to make such strings easier to write.
if you add an # before your string, \ will no long be the escape character, but now you have to escape " with ""
that means "\\\"" == #"\""" and "\\\\\"" == #"\\"""
so you could write Regex.Replace(html,#"\\""","\"")
which is easier to read then Regex.Replace(html,"\\\\\","\"")
i think i got it right this time :D

Resources