GO語言"os"包中"ExpandEnv"函數的用法及代碼示例。
用法:
func ExpandEnv(s string) string
ExpandEnv根據當前環境變量的值替換字符串中的${var}或$var。對未定義變量的引用被空字符串替換。
例子:
package main
import (
"fmt"
"os"
)
func main() {
os.Setenv("NAME", "gopher")
os.Setenv("BURROW", "/usr/gopher")
fmt.Println(os.ExpandEnv("$NAME lives in ${BURROW}."))
}
輸出:
gopher lives in /usr/gopher.
相關用法
- GO Expand用法及代碼示例
- GO Expm1用法及代碼示例
- GO Exp2用法及代碼示例
- GO Exp用法及代碼示例
- GO Ext用法及代碼示例
- GO Encode用法及代碼示例
- GO EncodeToString用法及代碼示例
- GO EscapeString用法及代碼示例
- GO Encoder用法及代碼示例
- GO Encoding.Decode用法及代碼示例
- GO Errorf用法及代碼示例
- GO Encoding.EncodeToString用法及代碼示例
- GO Equal用法及代碼示例
- GO Encoding.DecodeString用法及代碼示例
- GO ErrReader用法及代碼示例
- GO Encoding.Encode用法及代碼示例
- GO EqualFold用法及代碼示例
- GO EncodeRune用法及代碼示例
- GO PutUvarint用法及代碼示例
- GO Scanner.Scan用法及代碼示例
注:本文由純淨天空篩選整理自golang.google.cn大神的英文原創作品 ExpandEnv。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。