Fortran Coder

标题: 如何判断两个字符串完全相等? [打印本页]

作者: weixing1531    时间: 2023-2-26 13:44
标题: 如何判断两个字符串完全相等?
本帖最后由 weixing1531 于 2023-2-26 13:45 编辑

[Fortran] 纯文本查看 复制代码
character(:),allocatable::a,b
a="A"
b="A " !A后面加一个空格
write(*,*)a==b !你以为打印F 其实打印T
write(*,*)(a==b .AND. (len(a)==len(b))) !打印F

作者: Transpose    时间: 2023-2-26 17:20
是的,这是Fortran标准规定的

For a character relational intrinsic operation, the operands are compared one character at a time in order, beginning with the first character of each character operand. If the operands are of unequal length, the shorter operand is treated as if it were extended on the right with blanks to the length of the longer operand.  


如果长度不同,会自动扩展长度较短的那个,补齐空格

https://community.intel.com/t5/I ... parisons/m-p/798324




欢迎光临 Fortran Coder (http://bbs.fcode.cn/) Powered by Discuz! X3.2