我找不到一个专门构建的原语来做这个,甚至找不到一个
to-upper
to-report equal-ignore-case? [ str1 str2 ]
if (length str1 != length str2) [ report false ]
foreach (range length str1) [ i ->
let c1 (item i str1)
let c2 (item i str2)
; if c1 = c2, no need to do the `to-upper-char` stuff
if (c1 != c2 and to-upper-char c1 != to-upper-char c2) [
report false
]
]
report true
end
; this only works with a string length 1
to-report to-upper-char [ c ]
let lower "abcdefghijklmnopqrstuvwxyz"
let upper "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
let pos (position c lower)
report ifelse-value (is-number? pos) [ item pos upper ] [ c ]
end
那就
equal-ignore-case? "hello" "HELLO"
比较。
如果你关心有口音之类的角色,这显然是行不通的。我也不保证性能。