2016-08-07 173 views
1

我在做一個程序,我正在做一個'if'語句,我想要在它們之間使用'或'來完成許多布爾表達式。但我不知道如何。我的代碼:邏輯操作不起作用

if (input == "hello"* || input == "hi"*) { 
     output = "Hi!"; 
}; 

和錯誤,我得到:

Roxanne.vala:33.31-33.32: error: syntax error, expected identifier 
     if (input == "hello"* || input == "hi"*) { 
           ^^ 
Compilation failed: 1 error(s), 0 warning(s) 

我在做什麼錯?

回答

2

在字符串"hello""hi"之後有一個*。編譯器認爲你正在嘗試乘法。

+0

那是制動代碼嗎?我用它們作爲通配符。有替代品嗎? – user258456

+0

是的,這是問題所在。我能想到的唯一一種支持通配符的語言與您寫的內容類似。試試'input.has_prefix(「hello」)|| input.has_prefix( 「HI」)'。 – nemequ