Can I get access to an ascii character not in the standard set?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
Jer
Posts: 146
Joined: 23 Nov 2014 17:13
Location: California USA

Re: Can I get access to an ascii character not in the standard set?

#31 Post by Jer » 13 Nov 2018 01:44

Thanks Steffen for taking the time to look at this. Antonio asked for a simple example
and your solution ran flawlessly for that scenario.
In my bdrs (borders & boxes) script, strings of text from the command-line are converted
to multi-line fields when delimited by a colon.
The command-line entry {a quote ":and exclamation mark !
without substitution becomes
a_quote_" :and_exclamation_mark_!
except parsing that in a for loop, for %%a in (!string!) Do ... etc., causes chaos,
and the quote and emark have to be temporarily replaced. The string
would look like this: a_quote_X :and_exclamation_mark_[33]
and X represents the escape character that I am currently using to temporarily
replace the double quote.
The resulting array is examined for codes, like [33]. Codes are converted to the character
and written to an interim file which is read in with an adaptation of Antonio's SET /P code block,
which can read any character.
How do I display a literal colon with a command-line text entry when the colon is dedicated as a new line tag? [:]
Any character can be displayed by box-bracketing its code number. Dare I say "ascii" anymore?
Or just "characters" from now on.

Jerry

Aacini
Expert
Posts: 1564
Joined: 06 Dec 2011 22:15
Location: México City, México

Re: Can I get access to an ascii character not in the standard set?

#32 Post by Aacini » 13 Nov 2018 10:11

You not said that you want to "enter odd number of quotes as parameters in the command line". You said that the data will be read from the console or from a file.

The problem of get the command line parameters is solved as shown by aGerman in previous reply.

And about splitting a string at colons that may include quotes and exclamation marks:

Code: Select all

@echo off
setlocal

rem test command-line arguments: {a quote ":and exclamation mark !

set "args=%*"

set "i=0"
:nextPart
   set /A i+=1
   setlocal EnableDelayedExpansion
   for /F "tokens=1* delims=:" %%a in ("!args!") do (
      endlocal
      set "part[%i%]=%%a"
      set "args=%%b"
   )
if defined args goto nextPart

SET PART[
Output example:

Code: Select all

C:\Users\Antonio\Documents\test> test.bat {a quote ":and exclamation mark !
part[1]={a quote "
part[2]=and exclamation mark !
Antonio

Jer
Posts: 146
Joined: 23 Nov 2014 17:13
Location: California USA

Re: Can I get access to an ascii character not in the standard set?

#33 Post by Jer » 13 Nov 2018 17:51

I appreciate your advice and examples of code that has no need of replacing
special characters, including " and !. I've tried to revise code and remove
replacement, but errors occur and passing strings with special characters to functions
does not do what it is supposed to do. In the illustrative code below, you will see that
the args list is messed up inside the function.
Replacing poison characters temporarily works for me, so I'll stick with that.
Thanks again :)
Jerry

Code: Select all

@echo off
setlocal

set "string=/L50 /+ {a_quote_":and_exclamation_mark_!"
echo string: %string%
call :getParams "%string%" retVar
setlocal EnableDelayedExpansion
echo retVar: !retVar!
endlocal & endlocal & exit /b

:getParams
setlocal
echo args in function: %*
echo 1st arg: %1
echo 2nd arg: %2
endlocal & if "%~2" neq "" (set "%~2=success") else echo getParams failed & exit /b

Code: Select all

C:\Temp\DOSBatch>test1f
string: /L50 /+ {a_quote_":and_exclamation_mark_!
args in function: "/L50 /+ {a_quote_":and_exclamation_mark_!" retVar
1st arg: "/L50 /+ {a_quote_":and_exclamation_mark_!" retVar
2nd arg:
getParams failed
retVar:

Aacini
Expert
Posts: 1564
Joined: 06 Dec 2011 22:15
Location: México City, México

Re: Can I get access to an ascii character not in the standard set?

#34 Post by Aacini » 14 Nov 2018 07:34

I am afraid I don't understand your final goal... Do you want to evidence Batch file limitations or you want to solve your problem in a simple way? If you already have an intrinsically problematic string in a variable, why you expand it in a parameter? To show that this way don't works? :? Just pass the name of the variable in the parameter (in the same way you pass the name of retVar variable):

Code: Select all

@echo off
setlocal

set "string=/L50 /+ {a_quote_":and_exclamation_mark_!"
echo string: %string%
call :getParams string retVar
setlocal EnableDelayedExpansion
echo retVar: !retVar!
endlocal & endlocal & exit /b


:getParams
setlocal EnableDelayedExpansion
echo args in function: %*

echo 1st arg: %1
echo Value of 1st arg: !%1!
echo 2nd arg: %2
endlocal & if "%~2" neq "" (set "%~2=success") else echo getParams failed & exit /b
Since the beginning I asked you to "explain your basic problem in a simple way. Include a simple example". After a lot of posts you have not completed that request yet. Every time we show you the way to solve what we think is your problem, you show us a new small problem not described before... So, what's next? :|

Antonio

Jer
Posts: 146
Joined: 23 Nov 2014 17:13
Location: California USA

Re: Can I get access to an ascii character not in the standard set?

#35 Post by Jer » 14 Nov 2018 10:55

I did not know about passing a variable name to a function. Thanks for that revelation.
Sorry that I have not explained the final goal with a simple example.
The final goal is to display bordered content, like in the images, with any characters and
no crashes because of poison characters.

The code runs for the most part in enabledelayedexpansion and with code block levels, and we are
discussing solutions in a few lines of top-level code.
I will try your suggestion about the passing the variable name, but will have to wait until
I return from a 2-week vacation.

Aacini
Expert
Posts: 1564
Joined: 06 Dec 2011 22:15
Location: México City, México

Re: Can I get access to an ascii character not in the standard set?

#36 Post by Aacini » 14 Nov 2018 11:14

Jer wrote:
14 Nov 2018 10:55
I did not know about passing a variable name to a function. Thanks for that revelation.
In your last example:

Code: Select all

call :getParams "%string%" retVar
You are passing the name of retVar variable to the function, isn't it?
Jer wrote:
14 Nov 2018 10:55
Sorry that I have not explained the final goal with a simple example.
By "final goal" I am not talking about your program, but about what you expect from this thread. I am pretty sure that your code could be written with no character replacement, but if you are happy with your current solution then there is no need for further posts... It seems that I am more interested to solve this problem than you!

Antonio

Jer
Posts: 146
Joined: 23 Nov 2014 17:13
Location: California USA

Re: Can I get access to an ascii character not in the standard set?

#37 Post by Jer » 14 Nov 2018 18:32

About passing the variable name to a function and getting its value in the function,
there it was in front of me in strLen function.
Yes I am passing variable names to functions many times. It did not occur to me to use !%~1! inside
a function, as strLen does. I will try it when I return and see if passing the variable name will eliminate
poison character replacement.
Thanks.
Jerry

Jer
Posts: 146
Joined: 23 Nov 2014 17:13
Location: California USA

Re: Can I get access to an ascii character not in the standard set?

#38 Post by Jer » 18 Dec 2018 00:07

I removed double quote character temporary substitution from my batch code and found that tests and
my set of samples ran without error. Also, strings are now being passed to functions by reference.
The CHCP font issue is no longer mysterious (i.e., not unique to my PC) as explained by Dave in post #18.

Advice and tips from here have been very helpful. Thanks.
Jerry

Post Reply