Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
[COLOR=#2e8b57][b]character[/b][/color]([COLOR=#ff00ff]20[/color]) :: my_string
my_string [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]' Abc '[/color]
[COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]"my_string '"[/color], my_string, [COLOR=#ff00ff]"'"[/color]
[COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]"my_string '"[/color], [COLOR=#008080]trim[/color]([COLOR=#008080]adjustl[/color](my_string)), [COLOR=#ff00ff]"'"[/color]
[COLOR=#a020f0]end[/color]
$ g95 trim_ex.f95 -o trim_ex
$ trim_ex
my_string ' Abc '
my_string 'Abc'
character*256 str1,str2
integer*4 i,ls1,ls2
ls1 = len_trim(str1)
ls2 = 0
do i = 1,ls1
if(str1(i:i).ne.' ') then
ls2 = ls2 + 1
str2(ls2:ls2) = str1(i:i)
endif
enddo
! The new string "str2" contains no spaces and has length "ls2"
end
[COLOR=#a020f0]program[/color] remove_spaces
[COLOR=#2e8b57][b]implicit[/b][/color] [COLOR=#2e8b57][b]none[/b][/color]
[COLOR=#2e8b57][b]character[/b][/color]([COLOR=#ff00ff]30[/color]) :: my_string [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]' aaa bbb cc '[/color]
[COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]"my_string = '"[/color], my_string, [COLOR=#ff00ff]"'"[/color]
[COLOR=#0000ff]! sweep blanks from string[/color]
my_string [COLOR=#804040][b]=[/b][/color] sweep_blanks(my_string)
[COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]"my_string = '"[/color], [COLOR=#008080]trim[/color](my_string), [COLOR=#ff00ff]"'"[/color]
[COLOR=#a020f0]contains[/color]
[COLOR=#2e8b57][b]character[/b][/color]([COLOR=#ff00ff]30[/color]) [COLOR=#a020f0]function[/color] sweep_blanks(in_str)
[COLOR=#2e8b57][b]character[/b][/color]([COLOR=#804040][b]*[/b][/color]), [COLOR=#2e8b57][b]intent[/b][/color]([COLOR=#2e8b57][b]in[/b][/color]) :: in_str
[COLOR=#2e8b57][b]character[/b][/color]([COLOR=#ff00ff]30[/color]) :: out_str
[COLOR=#2e8b57][b]character[/b][/color] :: ch
[COLOR=#2e8b57][b]integer[/b][/color] :: j
out_str [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]" "[/color]
[COLOR=#804040][b]do[/b][/color] j[COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]1[/color], [COLOR=#008080]len_trim[/color](in_str)
[COLOR=#0000ff]! get j-th char[/color]
ch [COLOR=#804040][b]=[/b][/color] in_str(j:j)
[COLOR=#804040][b]if[/b][/color] (ch [COLOR=#804040][b].ne.[/b][/color] [COLOR=#ff00ff]" "[/color]) [COLOR=#804040][b]then[/b][/color]
out_str [COLOR=#804040][b]=[/b][/color] [COLOR=#008080]trim[/color](out_str) [COLOR=#804040][b]//[/b][/color] ch
[COLOR=#804040][b]endif[/b][/color]
sweep_blanks [COLOR=#804040][b]=[/b][/color] out_str
[COLOR=#804040][b]end do[/b][/color]
[COLOR=#a020f0]end function[/color] sweep_blanks
[COLOR=#a020f0]end program[/color] remove_spaces
$ g95 remove_spaces.f95 -o remove_spaces
$ remove_spaces
my_string = ' aaa bbb cc '
my_string = 'aaabbbcc'