在 nim 中加入数组
Join array in nim
我不太清楚为什么,但我不知道如何在 Nim 中连接数组,代码如下:
import std/strformat
proc check(to: int, multi: int, toreturn: string): string =
if to mod multi == 0:
return toreturn
else:
return ""
proc ifempty(str :string, num: int): string =
if len(str) == 0:
return fmt"{num}"
else:
return str
var i: int = 1
while i <= 100:
var checks = @[check(i, 3, "Fizz"), check(i, 5, "Buzz")]
let toecho = ifempty(checks.join(""), i)
echo(toecho)
inc(i)
我期待它加入数组,但我得到的只是错误
/home/runner/FavoriteJointLists/main.nim(18, 30) Error: attempting to call undeclared routine: 'join'
exit status 1
join
是在 std/strutils
中定义的,而不是 std/strformat
.
我不太清楚为什么,但我不知道如何在 Nim 中连接数组,代码如下:
import std/strformat
proc check(to: int, multi: int, toreturn: string): string =
if to mod multi == 0:
return toreturn
else:
return ""
proc ifempty(str :string, num: int): string =
if len(str) == 0:
return fmt"{num}"
else:
return str
var i: int = 1
while i <= 100:
var checks = @[check(i, 3, "Fizz"), check(i, 5, "Buzz")]
let toecho = ifempty(checks.join(""), i)
echo(toecho)
inc(i)
我期待它加入数组,但我得到的只是错误
/home/runner/FavoriteJointLists/main.nim(18, 30) Error: attempting to call undeclared routine: 'join' exit status 1
join
是在 std/strutils
中定义的,而不是 std/strformat
.