Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to write an integer value into a string with leading zeros?

Status
Not open for further replies.

mjs84

Aerospace
Aug 20, 2003
27
Help....

I am constructing a entity name in and I need to construct the name from strings and integers. This I know how to do, but I don't know how to get the leading zeros. For example:

integer*4 val1
character*3 chr1
character*3 chr2
character*10 ans

val1 = 1
chr1 = 'LST'

write(chr2,*) val1

ans = val1 // chr2 !gives me LST 1
!what I want is:
! LST001

Any help would, as always, be greatly appreciated.



 
Replies continue below

Recommended for you

mjs84,

WRITE (ans, '(a, i3.3)') chr1, val1

 
toog

Thanks a ton!!!!!

mjs84
 
Readers who wish to learn more how this works, please refer to internal files section of your favorite Fortran textbook. Thank you mjs84 and toog for addressing a valuable topic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor