Computing.Net > Forums > Programming > Batch Ssript String Formating

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch Ssript String Formating

Reply to Message Icon

Name: fsloke
Date: July 4, 2009 at 08:00:58 Pacific
OS: Windows XP
Subcategory: Batch
Comment:

Hi All,

Here some Question regarding String.
Question1
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?
Example:
set word =aeroplane
The value I want to get from "aeroplane" is "ro"

Thanks

-fsloke



Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: July 4, 2009 at 09:22:12 Pacific
Reply:

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

%var:~m,n%

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.

0

Response Number 2
Name: ghostdog
Date: July 4, 2009 at 09:34:29 Pacific
Reply:

@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


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch Ssript String Formating

batch: trim string error www.computing.net/answers/programming/batch-trim-string-error/16536.html

String Formatting in Java www.computing.net/answers/programming/string-formatting-in-java/7892.html

pascal string formatting www.computing.net/answers/programming/pascal-string-formatting-/4585.html