1
我想用$替換%符號。我嘗試做一個轉義字符(),但沒有奏效。我正在使用lua 5.1,並且出現格式錯誤。 (以'%'結尾)這使我煩惱,因爲我不知道如何解決它。我需要修復格式不正確的錯誤
io.write("Search: ") search = io.read()
local query = search:gsub("%", "%25") -- Where I put the % sign.
query = query:gsub("+", "%2B")
query = query:gsub(" ","+")
query = query:gsub("/", "%2F")
query = query:gsub("#", "%23")
query = query:gsub("$", "%24")
query = query:gsub("@", "%40")
query = query:gsub("?", "%3F")
query = query:gsub("{", "%7B")
query = query:gsub("}","%7D")
query = query:gsub("[","%5B")
query = query:gsub("]","%5D")
query = query:gsub(">", "%3E")
query = query:gsub("<", "%3C")
local url = "https://www.google.com/#q=" .. query
print(url)
輸出寫着:
malformed pattern (ends with '%')
感謝您幫助我! :) –