我想用一个解析文件的方法(指针)将数据加载到三个结构体中。我是新来的。
type a struct {
a string
}
type b struct {
b string
}
type c struct {
c string
}
func main() {
parse_file(filename)
}
//In below method, *l not sure how to define which can include 3 struct
func (l *l)parse_file(filename string) {
// open a file line by line
// if the line has value a then load into Struct a
//If the line has value b then load into Struct b
//If the line has value C then load into Struct c
}
字符串
1条答案
按热度按时间a0zr77ik1#
您可以定义一个结构体,它嵌入其他3个结构体
查看样品
test.txt
字符串
编码
型
如果要删除前缀
a -
、b -
或c -
,则可以使用TrimPrefix
将其删除型