Netlogo:有没有办法比较对大小写不敏感的字符串?

Netlogo: Is there a way to compare strings insensitive to capitalization?

我找不到比较两个不区分大小写的字符串的方法。我怎么能在 netlogo 中做到这一点?

我找不到专门构建的基元来执行此操作,甚至找不到 to-upper prim 可以使它相对容易。您可以制作一个粗略的实用程序来完成它:

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"进行比较。

如果您关心带有重音符号等的字符,这显然不起作用。我也不保证性能。