gpt4 book ai didi

string - 从字符串中提取引用部分

转载 作者:数据小太阳 更新时间:2023-10-29 03:41:39 26 4
gpt4 key购买 nike

<分区>

我正在尝试使用以下代码从字符串中提取引号部分:

package main
import ("fmt")
func main(){
var oristr = "This is a \"test string\" for testing only"
var quotedstr = ""
var newstr = ""
var instring = false
fmt.Println(oristr)
for i,c := range oristr {
fmt.Printf("Char number: %d; char: %c\n", i, c);
if c = `"` {
if instring
{instring=false}
else {instring=true}}
if instring
{quotedstr += c}
else {newstr += c}
}
fmt.Printf("Newstr: %s; quotedstr = %s", newstr, quotedstr )
}

但是,我收到以下错误:

# command-line-arguments
./getstring.go:11:14: syntax error: c = `"` used as value
./getstring.go:12:15: syntax error: unexpected newline, expecting { after if clause
./getstring.go:14:4: syntax error: unexpected else, expecting }
./getstring.go:15:3: syntax error: non-declaration statement outside function body

为什么我会收到此错误以及如何更正?

此外,这种方法是否可行,或者其他一些方法可能更好?

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com