MST

星途 面试题库

面试题:Fortran字符串拼接及子串提取问题

在Fortran中,给定两个字符串变量str1和str2,如何将它们拼接成一个新的字符串?另外,假设拼接后的字符串为full_str,如何提取从第5个字符开始长度为8的子串?请写出相应的Fortran代码实现。
17.7万 热度难度
编程语言Fortran

知识考点

AI 面试

面试题答案

一键面试
program string_manipulation
    implicit none
    character(len=50) :: str1, str2, full_str, sub_str
    str1 = 'Hello'
    str2 = ', World!'
    full_str = trim(str1) // trim(str2)
    sub_str = full_str(5:5 + 8 - 1)
    print *, '拼接后的字符串: ', full_str
    print *, '提取的子串: ', sub_str
end program string_manipulation