Remove all spaces from a string
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | s | String to remove spaces from |
String without spaces
Nodes of different colours represent the following:
Solid arrows point from a procedure to one which it calls. Dashed arrows point from an interface to procedures which implement that interface. This could include the module procedures in a generic interface or the implementation in a submodule of an interface in a parent module.
function removeSpaces(s) result(o)
!! Remove all spaces from a string
character(*),intent(in)::s
!! String to remove spaces from
character(:),allocatable::o
!! String without spaces
integer::sc,i,k
sc = 0
do k=1,len(s)
if( s(k:k)==' ' ) sc = sc+1
end do
o = repeat(' ',len(s)-sc)
i = 1
do k=1,len(s)
if( s(k:k)/=' ' ) then
o(i:i) = s(k:k)
i = i+1
end if
end do
end function removeSpaces