Embark on a journey of knowledge! Take the quiz and earn valuable credits.
Take A QuizChallenge yourself and boost your learning! Start the quiz now to earn credits.
Take A QuizUnlock your potential! Begin the quiz, answer questions, and accumulate credits along the way.
Take A QuizPlease log in to access this content. You will be redirected to the login page shortly.
LoginMicrosoft Microsoft DOS in Microsoft 3 years ago
As the title suggests, I want to reverse a string/variable in batch. Eg. the input is HELLO and the output is olleh. I know it is possible in vbs, but if possible, the script needs to be put in batch.Code: [Select]echo off
setlocal enabledelayedexpansion
set LINE=sdas sfsa fwfwa21321
set num=0
:LOOP
call set tmpa=%%line:~%num%,1%%%
set /a num+=1
if not "%tmpa%" equ "" (
set rline=%tmpa%%rline%
goto LOOP
)
echo %rline%
pauseThanks so much!anything can be put inside a put batch, including the cscript /wscript engine. Its better next to time state you want "pure cmd.exe commands without use of external TOOLS".
As always Devcom's effort is over and above. Does Devcom work for Microsoft?
C:\>type hi.bat
echo off
Code: [Select]setlocal enabledelayedexpansion
set line=%1
echo line = %line%
set num=0
:LOOP
call set tmpa=%%line:~%num%,1%%%
set /a num+=1
if not "%tmpa%" equ "" (
set rline=%tmpa%%rline%
goto LOOP
)
echo reverse = %rline%
Output:
C:\> hi.bat Hello
line = Hello
reverse = olleH
C:\>
_______________________________________ _
For a laugh I will show a newbie effort with batch:
C:\>type hello.bat
Code: [Select]echo off
REM http://www.dostips.com/DtTipsStringManipulation.php
setlocal enabledelayedexpansion
set x=%1
echo x = %x%
set x=%x:~-2,-1%
echo %x% > rev.txt
set x=%1
set x=%x:~-3,-2%
echo %x% >> rev.txt
set x=%1
set x=%x:~-4,-3%
echo %x% >> rev.txt
set x=%1
set x=%x:~-5,-4%
echo %x% >> rev.txt
set x=%1
set x=%x:~-6,-5%
echo %x% >> rev.txt
type rev.txt
C:\>hello.bat "Hello"
x = "Hello"
o
L
l
e
H
C:\>
Quote from: billrich on June 20, 2009, 02:54:12 PM
As always Devcom's effort is over and above. Does Devcom work for Microsoft?
Posted on 21 May 2022, this text provides information on Microsoft related to Microsoft DOS in Microsoft. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.
Turn Your Knowledge into Earnings.
No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.
Ready to take your education and career to the next level? Register today and join our growing community of learners and professionals.