Batch Script – Remove All Spaces
In this article, we are going to see how to remove all spaces from any string using Batch String.
Input: G e e k s f o r G e e k s Output: GeeksforGeeks
- By using ‘ set ‘ we are getting input of any string.
- Example: set str=input string
- In the next line using ‘ echo %str% ‘ we are printing our input string.
- In the next line of code, we are going to remove all spaces in the input string.
- Using ‘ := ‘ operator we are removing spaces in any string.
- We have to type any character between and = to remove that character from any given input string.
- For example: str=%str:e=% (this will remove e from the input string)
- So for removing spaces we will use ‘ : = ‘ .
- ‘ pause ‘ is used to hold the screen until any key is pressed.
@echo off set str=G e e k s f o r G e e k s echo %str% set str=%str: =% echo %str% pause
My Personal Notes arrow_drop_up