如何判断两个字符串完全相等?
本帖最后由 weixing1531 于 2023-2-26 13:45 编辑character(:),allocatable::a,b
a="A"
b="A " !A后面加一个空格
write(*,*)a==b !你以为打印F 其实打印T
write(*,*)(a==b .AND. (len(a)==len(b))) !打印F 是的,这是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/Intel-Fortran-Compiler/String-Comparisons/m-p/798324
页:
[1]