Batch Ssript String Formating

July 4, 2009 at 08:00:58
Specs: Windows XP
Hi All,

Here some Question regarding String.
How to formula a integer to a 5 digit value
1 to 00001
2 to 00002
10 to 00010

Question 2
How to get a substring of a String?
set word =aeroplane
The value I want to get from "aeroplane" is "ro"



See More: Batch Ssript String Formating

Report •

July 4, 2009 at 09:22:12
Question 1:

set int=12
set Fint=%int%
if %int% lss    10 set Fint=0%Fint%
if %int% lss   100 set Fint=0%Fint%
if %int% lss  1000 set Fint=0%Fint%
if %int% lss 10000 set Fint=0%Fint%
echo.Formatted %int% is %Fint%

Beware never perform arithmetic comparisons or operations with numbes with leading zeroes as they are interpreted as octals. Use formatted numbers for display only.

Question 2:

set mystring=aeroplane
echo.substring is %mystring:~2,2%

The general rule is


where m is the position of the substring starting from zero and n its lenght. Both m and n may assume negative value or be omitted. Type Set /? to know more.

Report •

July 4, 2009 at 09:34:29
@OP if its not for homework, you can use vbscript. see here for example for question 1 on padding with zeroes
Qns 2: you can use Mid() function to get substring
s = Mid(string,3,1)

GNU win32 packages | Gawk

Report •

Related Solutions

Ask Question