Utf 8 Liberty/ISE Eiffel中的If station错误
我对Utf 8 Liberty/ISE Eiffel中的If station错误,utf-8,eiffel,Utf 8,Eiffel,我对ifstation有问题 我有一个带有命令行参数和utf8(€-Symbol)的程序 错误出现在if语句中的works\u not class EURO insert ARGUMENTS create {ANY} make feature {ANY} make do works_not works end works_not local ok: BOOLEAN do
if
station有问题
我有一个带有命令行参数和utf8(€-Symbol)的程序
错误出现在if
语句中的works\u not
class EURO
insert ARGUMENTS
create {ANY}
make
feature {ANY}
make
do
works_not
works
end
works_not
local ok: BOOLEAN
do
print ("%N%NAnzahl Argumente : " + argument_count.to_string + "%N")
print ("%NArgument -> Programmname : " + argument(0))
print ("%NArgument -> Wert : " + argument(1))
print ("%NArgument -> Währung : " + argument(2) + "%N")
ok := argument(2) = "€"
print ("%NArgument(2) ist Euro ? " + ok.to_string + "%N%N")
print ("don't work")
io.put_new_line
if argument(2) = "€" then
euro_in_dm(argument(1).to_real)
else
dm_in_euro(argument(1).to_real)
end
end
works
do
print ("works ")
io.put_new_line
if argument_count /= 2 then
print("%N%N Error (1) %N%N")
else
inspect
argument(2)
when "€" then
euro_in_dm(argument(1).to_real)
when "DM","dm" then
dm_in_euro(argument(1).to_real)
else
print("%N%N Error (2) %N%N")
end
end
end
feature
euro_in_dm (a: REAL)
do
io.put_string("%N Euro -> DM ")
io.put_real(a * 1.95583)
io.put_string("%N%N")
end
dm_in_euro (a: REAL)
do
io.put_string("%N DM -> Euro ")
io.put_real(a / 1.95583)
io.put_string("%N%N")
end
end
问题出在比较运算符
参数(2)=“€”
中
在Eiffel中,字符串具有引用类型,因此相等运算符=
比较对字符串对象的引用,而不是它们的内容。如果要比较字符串值,则需要使用一个运算符~
,在检查两个操作数的类型是否完全相同后,在内部调用is_equal
,或者使用一个更健壮的版本is_string
(前提是在您的环境版本中可用)。总而言之,您可以尝试以下方法之一,而不是使用等式:
参数(2)。相同的字符串(€)
参数(2)~“€”
参数(2).是否等于(€)
参数\u 32
而不是参数。然后,“€”
应该写为{STRING_32}”€“
。而inspect
在EiffelStudio中对字符串不起作用,因此建议将if
与相同的字符串一起使用。