我正在尝试想出一个以字符串作为输入的动词 如果它是元音,则 printa 字符大写,即 (aeiou) 或小写 如果它是辅音。
s=:'authority'
t=:<&>s
│a│u│t│h│o│r│i│t│y│ NB. boxed s
预期输出为:AUthOrIty 我尝试使用控制流结构编写动词,使用 e.(membership) 来测试 char 是否 是元音,然后是
echo toupper s
但这不起作用。
您不需要对单个字符进行框选。
"0
将一次应用一个原子,在这种情况下,你的角色就是原子。
我会使用
e.
来检查某个字符是否是元音以及它是否适用 toupper
通过在测试中使用 ^:
强力连词 e.&vow
s=:'authority'
vow=:'aeiou' NB. define vowels
toupper^:(e.&vow)"0 s
AUthOrIty
正如鲍勃所说,没有理由对单个字符进行装箱。我更愿意在这里使用数据流而不是控制流:生成完整的大写字符串,然后使用
}
: 选择大小写适当的字符
s=:'authority'
s ,: toupper s
authority
AUTHORITY
s e.'aeiou'
1 1 0 0 1 0 1 0 0
(s e.'aeiou')} s ,: toupper s
AUthOrIty
参见nuvoc。
使用
{
: 功能等效的替代方案
s ,. toupper s
aA
uU
tT
hH
oO
rR
iI
tT
yY
(s e.'aeiou') {"_1 s ,. toupper s
AUthOrIty
另一种方法:
(tolower`toupper)@.(e.&'aeiou')"0 'aaaabbBBCCccceeee'
AAAAbbbbcccccEEEE