Fortran Coder

查看: 1599|回复: 1
打印 上一主题 下一主题

[通用算法] 如何判断两个字符串完全相等?

[复制链接]

127

帖子

35

主题

1

精华

大师

F 币
1153 元
贡献
592 点
跳转到指定楼层
楼主
发表于 2023-2-26 13:44:25 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 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
分享到:  微信微信
收藏收藏 点赞点赞 点踩点踩

159

帖子

2

主题

1

精华

大师

Vim

F 币
961 元
贡献
469 点

规矩勋章

沙发
发表于 2023-2-26 17:20:47 | 只看该作者
是的,这是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
您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

捐赠本站|Archiver|关于我们 About Us|小黑屋|Fcode ( 京ICP备18005632-2号 )

GMT+8, 2024-4-25 23:47

Powered by Tencent X3.4

© 2013-2024 Tencent

快速回复 返回顶部 返回列表