with special characters that may appear in the text displayed on a uniform color panel.
The problem: when the text contains %, >, or %, either one or several, my string of text
padded with leading and trailing blanks is short 1 character. The color panel is therefore short by 1 character.
I check the length of the string of text, calculate the spaces right and left for centering, add 2 columns
for left and right margins, then feed the variables to the color function:
Call :color %colors% "%spacesLEFT%%str%%spacesRIGHT%"
I would like to be able to test the text for <, > or % and add an additional blank space to
the string if any of the characters are found. Here is my test code to find the characters:
Code: Select all
@echo off
setlocal EnableDelayedExpansion
Set "txt=> Game Over <"
Call:isSpecChar "%txt%"
Set "txt=You scored 100%%%%."
Call :isSpecChar "%txt%"
Set "txt=Goodbye."
Call :isSpecChar "%txt%"
endlocal & exit /b
:isSpecChar
setlocal DisableDelayedExpansion
rem check for chars % < and >
Set "specialChar=FALSE"
Set "STRING=%~1"
Set "STRING=%STRING:<=%"
If Not ."%STRING%".==.%1%. Set "specialChar=TRUE"& GoTo:endISC
Set "STRING=%STRING:>=%"
If Not ."%STRING%".==.%1%. Set "specialChar=TRUE"& GoTo:endISC
Set "STRING=%STRING:^%=%"
If Not ."%STRING%".==.%1%. Set "specialChar=TRUE"
:endISC
echo was special character found? !specialChar!
endlocal & exit /b
and the error:
C:\Temp\>If Not ."> Game Over ".==."> Game Over <"endISC