Can I get access to an ascii character not in the standard set?
Moderator: DosItHelp
Re: Can I get access to an ascii character not in the standard set?
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
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
Re: Can I get access to an ascii character not in the standard set?
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:
Output example:
Antonio
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[
Code: Select all
C:\Users\Antonio\Documents\test> test.bat {a quote ":and exclamation mark !
part[1]={a quote "
part[2]=and exclamation mark !
Re: Can I get access to an ascii character not in the standard set?
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
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:
Re: Can I get access to an ascii character not in the standard set?
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):
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
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
Antonio
Re: Can I get access to an ascii character not in the standard set?
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.
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.
Re: Can I get access to an ascii character not in the standard set?
In your last example:
Code: Select all
call :getParams "%string%" retVar
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
Re: Can I get access to an ascii character not in the standard set?
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
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
Re: Can I get access to an ascii character not in the standard set?
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
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
Re: Can I get access to an ascii character not in the standard set?
As posted in this forum, TinyPic image hosting is no longer available and this caused
my images to go away.
These links, after right clicking and choosing open in a new tab, pull up my project sample images for me.
Clicking on the link just shows a white screen on my Windows 10 PC w/Firefox browser.
https://photos.google.com/photo/AF1QipM ... CIDZDop3ox
https://photos.google.com/photo/AF1QipM ... xkA3-Vl9JR
https://photos.google.com/photo/AF1QipM ... 1K1M-L-CDo
Batch code project update:
Borders/Frames/Patterns, etc. tools and 16.7 million colors (9,995 named colors) tools almost ready to move into the code-cleanup and much-testing stage.
Jerry
edit: oops! Links do not work as I expected. It worked until I was not logged into gmail
edit: 6/27/2020 maybe free dropbox account will allow sharing image files.
https://www.dropbox.com/s/4pnrq78ytl7ym ... pg?dl=true
https://www.dropbox.com/s/ml465rw1by6sc ... pg?dl=true
https://www.dropbox.com/s/deljdtm75tp3e ... pg?dl=true
https://www.dropbox.com/s/s6xt9ayklrxdi ... pg?dl=true
https://www.dropbox.com/s/4tem1nveh6yjm ... pg?dl=true
https://www.dropbox.com/s/xlnn32rb4e4ur ... pg?dl=true
6/3/2021 .. never ending project continues .. using Mediafire to share screen shots.
right-click on link and choose Open in New Tab
https://www.mediafire.com/folder/yyuh8l ... /Documents
my images to go away.
These links, after right clicking and choosing open in a new tab, pull up my project sample images for me.
Clicking on the link just shows a white screen on my Windows 10 PC w/Firefox browser.
https://photos.google.com/photo/AF1QipM ... CIDZDop3ox
https://photos.google.com/photo/AF1QipM ... xkA3-Vl9JR
https://photos.google.com/photo/AF1QipM ... 1K1M-L-CDo
Batch code project update:
Borders/Frames/Patterns, etc. tools and 16.7 million colors (9,995 named colors) tools almost ready to move into the code-cleanup and much-testing stage.
Jerry
edit: oops! Links do not work as I expected. It worked until I was not logged into gmail
edit: 6/27/2020 maybe free dropbox account will allow sharing image files.
https://www.dropbox.com/s/4pnrq78ytl7ym ... pg?dl=true
https://www.dropbox.com/s/ml465rw1by6sc ... pg?dl=true
https://www.dropbox.com/s/deljdtm75tp3e ... pg?dl=true
https://www.dropbox.com/s/s6xt9ayklrxdi ... pg?dl=true
https://www.dropbox.com/s/4tem1nveh6yjm ... pg?dl=true
https://www.dropbox.com/s/xlnn32rb4e4ur ... pg?dl=true
6/3/2021 .. never ending project continues .. using Mediafire to share screen shots.
right-click on link and choose Open in New Tab
https://www.mediafire.com/folder/yyuh8l ... /Documents