* Marvin Renich <m...@renich.org> [240220 10:52]:
> * Sagar Byahatti <sagarbyaha...@gmail.com> [240220 08:22]:
> >  package main
> > 
> > import "fmt"
> > 
> > func main() {
> > 
> >     var projectName = "APY"
> >     var sub = 50
> > 
> >     fmt.Println("Welcome to", projectName, " the number of subscriber is ", 
> > sub)
> >     fmt.Println("Enter your name: ")
> >     var userName string
> > 
> >     fmt.Scan(&userName)
> > 
> >     fmt.Printf("%v, your PRAN Number is", userName)
> > 
> > }
> 
> fmt.Scan is probably not what you want, though if I run your program and
> type a single word (no spaces) and then a newline, I get the result that
> I think you are expecting.
> 
> You probably want to look at the bufio package, and specifically the
> Reader.ReadString method.  Something like (untested)
> 
>     var input = bufio.NewReader(os.Stdin)
>     var userName, err = input.ReadString('\n')

Then use strings.TrimSpace on userName to get rid of the trailing '\n'
and any other leading or trailing blanks:

    userName = strings.TrimSpace(userName)

Don't forget to check err for non-nil and handle the error accordingly.

...Marvin

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/ZdTPThtHUdDnioHq%40basil.wdw.

Reply via email to