在go中使用lua示例, 基于gopher-lua!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 rivejä
1.1 KiB

4 vuotta sitten
  1. local strings = require("strings")
  2. local str = "hello world"
  3. local t = strings.split(str, " ")
  4. local count_t = 0
  5. for k, v in pairs(t) do
  6. count_t = count_t + 1
  7. if k == 1 then if not(v == "hello") then error("strings.split()") end end
  8. if k == 2 then if not(v == "world") then error("strings.split()") end end
  9. end
  10. if not(count_t == 2) then error("string.split()") end
  11. print("done: strings.split()")
  12. if not(strings.has_prefix(str, "hello")) then error("strings.has_prefix()") end
  13. if not(strings.has_suffix(str, "world")) then error("strings.has_suffix()") end
  14. print("done: strings.has_suffix, strings.has_prefix")
  15. if not(strings.trim(str, "world") == "hello ") then error("strings.trim()") end
  16. if not(strings.trim(str, "hello ") == "world") then error("strings.trim()") end
  17. if not(strings.trim_prefix(str, "hello ") == "world") then error("strings.trim()") end
  18. if not(strings.trim_suffix(str, "hello ") == "hello world") then error("strings.trim()") end
  19. print("done: strings.trim()")
  20. if not(strings.contains(str, "hello ") == true) then error("strings.contains()") end
  21. print("done: strings.contains()")