gpt4 book ai didi

斯卡拉 : Enumeration with special characters

转载 作者:行者123 更新时间:2023-12-02 18:47:19 26 4
gpt4 key购买 nike

如何创建和使用其值中包含一些特殊字符和空格的枚举?

object Bots extends Enumeration {
type Bots = Value
val `apis-google`, `mediapartners-google`, `adsbot-google-mobile-apps`, `google favicon` = Value
}

当调用这个枚举时,特殊字符似乎被一些内部标识符替换或改变了它们的编码:

for (bot <- Bots.values) println(bot)

输出:

apis$minusgoogle 
mediapartners$minusgoogle
adsbot$minusgoogle$minusmobile$minusapps
google$u0020favicon

编辑:我使用 scala 2.2

最佳答案

$ scala
Starting scala3 REPL...
scala> object Bots extends Enumeration {
| type Bots = Value
| val `apis-google`: Bots = Value(0, "apis-google")
| val `mediapartners-google`: Bots = Value(1, "mediapartners-google")
| val `adsbot-google-mobile-apps`: Bots = Value(2, "adsbot-google-mobile-apps")
| val `google favicon`: Bots = Value(3, "google favicon")
| }
|
// defined object Bots

scala> for (bot <- Bots.values) println(bot)
|
apis-google
mediapartners-google
adsbot-google-mobile-apps
google favicon

关于斯卡拉 : Enumeration with special characters,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67263421/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com