假设我有一个字符串,其中包含"## ##"
中我想要读取的stdin
形式,例如"15 16"
。这很简单:
I HAS A STRINGY
GIMMEH STRINGY
从stdin
获取整行并将其存储到字符串中,对不起, YARN - 称为STRINGY
。
如何提取字符串中的两个整数?我希望能够存储15和16作为整数(LULZ I MEANS NUMBR)。
答案 0 :(得分:16)
简答:
您无法在LOLCODE 1.2中执行此操作。
答案很长:
由于没有YARN
操作函数,并且无法在建议的1.3规范中将YARN
转换为类似BUKKIT
的内容(因此我们可以将字符串模拟为{ {1}}个字符),无法从字符串中提取数字。
只使用1.2规范,我们仍然能够完成这项工作,我猜......
由于字符串连接在1.2中已经存在BUKKIT
,理论上你可以保留变量SMOOSH ... MKAY
到str01
,然后......
str99
接下来,获取NUMBR ...
IM IN YR readloop UPPIN YR throwawayvariable WILE BOTH OF NOT broken AN DIFFRINT currentyarn AN STRINGY
str01, WTF?
OMG "Z"
str99 R str98
str98 R str97
str97 R str96
...
str02 R str01
str01 R ""
GTFO
OMG "Y"
str01 R "Z";
GTFO
OMG "X"
str01 R "Y";
GTFO
...
OMG "0"
str01 R "1";
GTFO
OMG ""
str01 R "0"
GTFO
OMGWTF
I HAS A ERRORMSG
ERRORMSG R SMOOSH "I DUNNO WAT U SAY, illegal character", str01 MKAY
VISIBLE ERRORMSG
broken R WIN
GTFO
OIC
currentyarn R SMOOSH str01, str02, str03, str04, ..., str98, str99 MKAY
IM OUTTA YR readloop
最后,你想用它们做什么。
NOT broken, O RLY? YA RLY
yarnnumber R ""
done R FAIL
IM IN YR parseloop UPPIN YR otherthrowaway WILE NOT done
EITHER OF BOTH SAEM str01 AN " " AN BOTH SAEM str01 AN "", O RLY? YA RLY
number1 R 0
DIFFRINT yarnnumber AN "", O RLY? YA RLY
number1 R MAEK yarnnumber A NUMBR
OIC
done R WIN
MEBBE DIFFRINT str01 AN ""
yarnnumber R SMOOSH yarnnumber, str01 MKAY
OIC
str01 R str02
str02 R str03
str03 R str04
...
str98 R str99
str99 R ""
IM OUTTA YR parseloop
yarnnumber R ""
done R FAIL
IM IN YR parseloop2 UPPIN YR otherthrowaway2 WILE NOT done
EITHER OF BOTH SAEM str01 AN " " AN BOTH SAEM str01 AN "", O RLY? YA RLY
number2 R 0
DIFFRINT yarnnumber AN "", O RLY? YA RLY
number2 R MAEK yarnnumber A NUMBR
OIC
done R WIN
MEBBE DIFFRINT str01 AN ""
yarnnumber R SMOOSH yarnnumber, str01 MKAY
OIC
str01 R str02
str02 R str03
str03 R str04
...
str98 R str99
str99 R ""
IM OUTTA YR parseloop2
OIC
对于I HAZ A result
result R SUM OF number1 AN number2
VISIBLE result
,请填写使用...
变量的其余语句。
如果您要使用此功能,我建议您使用一些东西为您生成LOLCODE,手动编写这样做是不可行的。特别是如果你必须支持更长的输入行,如255或1024个字符。