To combine string and integer in F90

  • Follow


Hello all,

I would like to combine string and an integer number to write the
result as string.
Suppose, my string is 'str' and the integer number is 123, I would
like to combine them and write as 'str_123'.

I hope you have an answer for my query.

With thanks and regards
arun
0
Reply arun 11/29/2010 2:59:21 AM

"arun" <arunkumar.cr@gmail.com> wrote in message 
news:d11390c1-5423-4d5c-b4ef-e7f444804eda@j32g2000prh.googlegroups.com...
>
> Hello all,
>
> I would like to combine string and an integer number to write the
> result as string.
> Suppose, my string is 'str' and the integer number is 123, I would
> like to combine them and write as 'str_123'.
>
> I hope you have an answer for my query.
>
> With thanks and regards
> arun

look up "internal write"


0
Reply e 11/29/2010 3:44:40 AM


On 11/28/2010 6:59 PM, arun wrote:
>
> Hello all,
>
> I would like to combine string and an integer number to write the
> result as string.
> Suppose, my string is 'str' and the integer number is 123, I would
> like to combine them and write as 'str_123'.
>
> I hope you have an answer for my query.
>
> With thanks and regards
> arun

one way (not the best way, I am sure, but for now will do)

---------------------
PROGRAM Main
  implicit none
  character*3 int_as_String
  character*7 all

  write(int_as_string, fmt='(I3)') 123
  all='str_'//int_as_string

  write(*,*) all

END PROGRAM Main
---------------------

--Nasser

0
Reply Nasser 11/29/2010 4:00:35 AM

On Nov 28, 11:00=A0pm, "Nasser M. Abbasi" <n...@12000.org> wrote:
> On 11/28/2010 6:59 PM, arun wrote:
>
>
>
> > Hello all,
>
> > I would like to combine string and an integer number to write the
> > result as string.
> > Suppose, my string is 'str' and the integer number is 123, I would
> > like to combine them and write as 'str_123'.
>
> > I hope you have an answer for my query.
>
> > With thanks and regards
> > arun
>
> one way (not the best way, I am sure, but for now will do)
>
> ---------------------
> PROGRAM Main
> =A0 implicit none
> =A0 character*3 int_as_String
> =A0 character*7 all
>
> =A0 write(int_as_string, fmt=3D'(I3)') 123
> =A0 all=3D'str_'//int_as_string
>
> =A0 write(*,*) all
>
> END PROGRAM Main
> ---------------------
>
> --Nasser

Possibly it could be a problem for the OP if the numeric string were
less than 100
and blanks were placed in the output string before the digits. That
could be
avoided if the format were "I3.3" rather tnan "I3". The I3.3 format
will
pad the output string with leading zeros, at least for F90 and later.

Daniel Feenberg

0
Reply feenberg 11/29/2010 2:10:56 PM

feenberg <feenberg@gmail.com> wrote:

> The I3.3 format will pad the output string with leading zeros, at least
> for F90 and later.

That's also valid in f77.

-- 
Richard Maine                    | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle           |  -- Mark Twain
0
Reply nospam 11/29/2010 4:03:42 PM

On Nov 29, 2:10=A0pm, feenberg <feenb...@gmail.com> wrote:

> Possibly it could be a problem for the OP if the numeric string were
> less than 100
> and blanks were placed in the output string before the digits. That
> could be
> avoided if the format were "I3.3" rather tnan "I3". The I3.3 format
> will
> pad the output string with leading zeros, at least for F90 and later.



> Possibly it could be a problem for the OP if the numeric string were
> less than 100
> and blanks were placed in the output string before the digits. That
> could be
> avoided if the format were "I3.3" rather tnan "I3". The I3.3 format
> will
> pad the output string with leading zeros, at least for F90 and later.
>
> Daniel Feenberg


Alternatively if you don't want to pad with zeros, the I0 edit
descriptor of modern Fortran is useful here:

  implicit none
  character(len=3D8)  :: oldstr
  character(len=3D16) :: newstr
  integer :: n

  oldstr =3D 'str'
  n =3D 123

  write(newstr, '(A,I0)') trim(oldstr), n

  write(*,'(A)') trim(newstr)

  end


David Kinniburgh
0
Reply David 11/30/2010 2:38:13 AM

5 Replies
910 Views

(page loaded in 0.145 seconds)

Similiar Articles:













7/20/2012 7:20:01 PM


Reply: