想要達(dá)到我正在用 Go 構(gòu)建一個(gè)應(yīng)用程序。它是從 excel 文件創(chuàng)建一個(gè) ruby 文件。如果xx中有值,我想把它放在數(shù)據(jù)中,如果它是空白的,我想跳過這個(gè)過程。但是,如果我如下所示輸入 nil,則會(huì)出現(xiàn)錯(cuò)誤。xx = xx + 19if row[xx] ! = nil { data["IndustryId"] = row[xx]; }invalid operation: row[xx] != nil (mismatched types string and nil)我希望你能幫助我。代碼測(cè)試.gofunc main() { excel_file, err := excelize.OpenFile("./excel/data.xlsx") if err != nil { fmt.Println(err) return } seeds := make([]string, 0, 1000) seeds = append(seeds, "# Seed") seeds = append(seeds, "# " + time.Now().Format("RFC3339")) seeds = append(seeds, "") tpl := template.Must(template.ParseFiles(`test.tmpl`)) rows, err := excel_file.GetRows("Test") for i, row := range rows { if i != 0 { xx := 2 data := map[string]string{ "Id": row[xx], } xx = xx + 19 if row[xx] != nil { data["IndustryId"] = row[xx]; } if err := tpl.Execute(&output, data); err != nil { fmt.Println(err) return } seeds = append(seeds, output.String()) } } export_file("./seeds/import_test.rb", seeds)}
如何檢查字符串中的變量是否為空白
人到中年有點(diǎn)甜
2022-10-24 16:20:08