Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fmt: Sscanf , str include " #12564

Closed
scroot opened this issue Sep 10, 2015 · 3 comments
Closed

fmt: Sscanf , str include " #12564

scroot opened this issue Sep 10, 2015 · 3 comments

Comments

@scroot
Copy link

@scroot scroot commented Sep 10, 2015

package main

import (
    "fmt"
    "os"
    "os/exec"
)

func main() {

    cmd := exec.Command(`c:\windows\system32\where.exe`, `/f`, "/t", "*.txt")
    buf, err := cmd.Output()
    if err != nil {
        fmt.Println(err)
        return
    }
    var i int
    var str string
    fmt.Sscanf(string(buf), `%d   2015/8/23      12:59:38  "%s"`, &i, &str)
    fmt.Println(i, str)
    fmt.Fprintf(os.Stdout, "%s", buf)

}

运行...

1649 C:\Windows\System32\WindowsCodecsRaw.txt"
1649 2015/8/23 12:59:38 "C:\Windows\System32\WindowsCodecsRaw.txt"

@adg adg changed the title fmt.Sscanf , str include " fmt: Sscanf , str include " Sep 10, 2015
@scroot
Copy link
Author

@scroot scroot commented Sep 10, 2015

system: window 10 x64
go version: go1.5.1 windows/amd64

@adg
Copy link
Contributor

@adg adg commented Sep 10, 2015

What's the issue?

@minux minux closed this Sep 10, 2015
@minux
Copy link
Member

@minux minux commented Sep 10, 2015

I think what the OP meant is this program:
http://play.golang.org/p/fO2iXLrGUU

fmt.Sscanf(1649 2015/8/23 12:59:38 "C:\Windows\System32\WindowsCodecsRaw.txt", %d 2015/8/23 12:59:38 "%s", &i, &str)

The scanned str will contain the right double-quote character.

This is working as intended. Scanf %s will keep scanning until it encounters
any space characters.

Quote https://golang.org/pkg/fmt
...
%s and %v on strings scan a space-delimited token
...

PS: Please ask questions like this on the mailing list. If you use English,
golang-nuts, or if you prefer Chinese, golang-china.

@golang golang locked and limited conversation to collaborators Sep 22, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.