Indents each line in the provided string.

Use strings.Replace() to prepend i to each line.

代码实现

import "strings"

func Indent(s, i string) string {
    return i + strings.Replace(s, "\n", "\n"+i, -1)
}

使用样例

Indent("Lorem\nIpsum","_") // "_Lorem\n_Ipsum"