how to remove dot and colon in text color use?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
One Batch
Posts: 8
Joined: 30 Aug 2015 04:58

how to remove dot and colon in text color use?

#1 Post by One Batch » 30 Aug 2015 05:38

Code: Select all

echo.
CALL :ColorText 0B "color"
set /p ".=  " <nul
CALL :ColorText 0C "this"
set /p ".=  " <nul
CALL :ColorText 01 "line" end
set /p ".=  " <nul
echo.
echo.
pause
exit
:ColorText [%1 = Color] [%2 = Text]
set /p ".=." > "%~2" <nul
findstr /v /a:%1 /R "^$" "%~2" nul 2>nul
set /p ".={BS}{BS}" <nul
if "%3" == "end" set /p ".=  " <nul
del "%~2" >nul 2>nul
exit /b


This code I am using result in displaying the text:
colorthisline:.

I want to get rid of the ":" and "." characters that appear in the output.

When I add another text to the code to color..

Code: Select all

CALL :ColorText 0B "color"
set /p ".=  " <nul
CALL :ColorText 0C "this"
set /p ".=  " <nul
CALL :ColorText 0E "first"
set /p ".=  " <nul
CALL :ColorText 01 "line" end
set /p ".=  " <nul


Which is the text "first". The output will be:
colorthisfirstline:.

I want to have the output as:
colorthisfirstline

So without the ":" and the "." How can I make this possible?

Thanks

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: how to remove dot and colon in text color use?

#2 Post by foxidrive » 30 Aug 2015 08:45

I believe the current version is V23c - is that the one you are using?

Code: Select all

:Color
:: v23c
:: Arguments: hexColor text [\n] ...
:: \n -> newline ... -> repeat
:: Supported in windows XP, 7, 8.
:: This version works using Cmd /U
:: In XP extended ascii characters are printed as dots.
:: For print quotes, use empty text.


See viewtopic.php?p=41155#p41155

One Batch
Posts: 8
Joined: 30 Aug 2015 04:58

Re: how to remove dot and colon in text color use?

#3 Post by One Batch » 30 Aug 2015 12:47

No. I write the code in a notepad. Save it as colortext.bat
I am not used to the program that you speak about.
Can the result i ask for be done in a regular textfile?
It seems the code for the program you mention is a bit different from how i wrote the code.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: how to remove dot and colon in text color use?

#4 Post by foxidrive » 30 Aug 2015 13:03

carlos' batch file at that link is designed to print coloured text, and is in a regular text file.

This is the same code here with the top part added/changed - your code doesn't work as it is pasted so I am guessing what you want to see on the screen.

Code: Select all

@Echo Off
CALL :Color B "color "
CALL :Color C "this "
CALL :Color E "first "
CALL :Color 1 "line " \n

CALL :Color 4 "color "
CALL :Color 6 "this "
CALL :Color 2 "first "
CALL :Color e "line "
CALL :Color 1 " " \n
CALL :Color 1 " " \n

CALL :Color A "color " 3 "this " F "first " 2 "line "

Pause >Nul
Exit /B


:Color
:: v23c
:: Arguments: hexColor text [\n] ...
:: \n -> newline ... -> repeat
:: Supported in windows XP, 7, 8.
:: This version works using Cmd /U
:: In XP extended ascii characters are printed as dots.
:: For print quotes, use empty text.
SetLocal EnableExtensions EnableDelayedExpansion
Subst `: "!Temp!" >Nul &`: &Cd \
SetLocal DisableDelayedExpansion
Echo(|(Pause >Nul &Findstr "^" >`)
Cmd /A /D /C Set /P "=." >>` <Nul
For /F %%# In (
'"Prompt $H &For %%_ In (_) Do Rem"') Do (
Cmd /A /D /C Set /P "=%%# %%#" <Nul >`.1
Copy /Y `.1 /B + `.1 /B + `.1 /B `.3 /B >Nul
Copy /Y `.1 /B + `.1 /B + `.3 /B `.5 /B >Nul
Copy /Y `.1 /B + `.1 /B + `.5 /B `.7 /B >Nul
)
:__Color
Set "Text=%~2"
If Not Defined Text (Set Text=^")
SetLocal EnableDelayedExpansion
For %%_ In ("&" "|" ">" "<"
) Do Set "Text=!Text:%%~_=^%%~_!"
Set /P "LF=" <` &Set "LF=!LF:~0,1!"
For %%# in ("!LF!") Do For %%_ In (
\ / :) Do Set "Text=!Text:%%_=%%~#%%_%%~#!"
For /F delims^=^ eol^= %%# in ("!Text!") Do (
If #==#! EndLocal
If \==%%# (Findstr /A:%~1 . \` Nul
Type `.3) Else If /==%%# (Findstr /A:%~1 . /.\` Nul
Type `.5) Else (Cmd /A /D /C Echo %%#\..\`>`.dat
Findstr /F:`.dat /A:%~1 .
Type `.7))
If "\n"=="%~3" (Shift
Echo()
Shift
Shift
If ""=="%~1" Del ` `.1 `.3 `.5 `.7 `.dat &Goto :Eof
Goto :__Color

One Batch
Posts: 8
Joined: 30 Aug 2015 04:58

Re: how to remove dot and colon in text color use?

#5 Post by One Batch » 31 Aug 2015 08:31

Alright, I give you the whole code. This is saved in a notepad as colortest.bat

Code: Select all

@echo off
echo.
CALL :ColorText 0B "color"
set /p ".=  " <nul
CALL :ColorText 0C "this"
set /p ".=  " <nul
CALL :ColorText 01 "line"
set /p ".=  " <nul
CALL :ColorText 0E "first" end
echo.
echo.
pause
exit
:ColorText [%1 = Color] [%2 = Text]
set /p ".=." > "%~2" <nul
findstr /v /a:%1 /R "^$" "%~2" nul 2>nul
set /p ".=" <nul
if "%3" == "end" set /p ".=  " <nul
del "%~2" >nul 2>nul
exit /b

The output of this code is:
colorthislinefirst:.

I want the output to be:
colorthislinefirst

What is wrong in this code that causes the colon and the dot to be added at the end in the output?
In the original code that I used. I added two backspace symbol characters after the equal-sign in the line with "set".
Below the line with findstr. The adding of the BS symbol character was done in the Notepad++ editor.
Though with the BS symbol character added it only removes the colon and the dot at the end of these three words: color this line
After the word: first will be a colon and a dot. How can I remove those?

The option that you give is a somewhat complicated solution.
I dont understand the code starting from the :color label. And further down at the :__color label.
I dont know what happens there. The same method is used to color using the findstr command. I understand that.
Though I find it more difficult then the code I have here. And think I just overlooked a small thing in the code I used.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: how to remove dot and colon in text color use?

#6 Post by foxidrive » 31 Aug 2015 16:43

One Batch wrote:Though I find it more difficult then the code I have here. And think I just overlooked a small thing in the code I used.


carlos has made his code more robust, fixed different character problems and is able to work in various versions of Windows.

You may fix your particular issue and then find another problem - so why not use a solution that has been tested and fixed in numerous ways?

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

Re: how to remove dot and colon in text color use?

#7 Post by Aacini » 31 Aug 2015 17:47

@One Batch,

In this line:

Code: Select all

if "%3" == "end" set /p ".=  " <nul

Change the value between quotes from "<dot><equal><space><space>" to "<dot><equal><dot><BS><space><space>"

Antonio

One Batch
Posts: 8
Joined: 30 Aug 2015 04:58

Re: how to remove dot and colon in text color use?

#8 Post by One Batch » 01 Sep 2015 03:28

@aacini
Thanks i give that a try.

Fox
For my taste of coding i want a less robust code.
And the solution aacini gave is fine.
Though i can explore the code of carlos.
Im not that advanced in batchfiles to fully understand and use carlos code.
One issue with the code you showed me. In the output the text has a space between the words.

How to output the words without a space in between and on one line aswell using the code of carlos?
I could consider this for a later time.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: how to remove dot and colon in text color use?

#9 Post by foxidrive » 01 Sep 2015 05:25

One Batch wrote:Im not that advanced in batchfiles to fully understand and use carlos code.


You can use the simpler code - I'm merely pointing out that you are likely to find other problems if you use an extensive set of characters, that is already fixed.

One issue with the code you showed me. In the output the text has a space between the words.
How to output the words without a space in between and on one line aswell using the code of carlos?
I could consider this for a later time.


Try this at the top of carlos' code.

Code: Select all

@Echo Off
CALL :Color 0B "color"
CALL :Color 0C "this"
CALL :Color 0E "first"
CALL :Color 01 "line" \n

Pause
Exit /B

Post Reply