FAQ
Hello,

I am trying to compare two string, but I guess one has a word wrap at the
end and so even if they look similar my condition never works.

Example :

fmt.Printf("|%s|",stringA[10])

fmt.Printf("|%s|",stringB[10][0])



Returns :

10.11.204.34||10.11.204.34

Later if my code I have a "if outputNoPriv[i] == outputPriv[j][0] {"


But this condition is never true and the program never goes inside.


I see only one possibility, it is the "breadline" after the ".34"


How could I solve this problem ?


Thank you.

--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Stéphane phenetas at Sep 4, 2015 at 10:04 pm
    Hey, sorry for posting so fast. After reading multiple Google results, I
    have found the solution here
    : http://stackoverflow.com/questions/22688010/how-to-trim-leading-and-trailing-white-spaces-of-a-string-in-golang

    "For example,

    package main
    import (
         "fmt"
         "strings")

    func main() {
         s := "\t Hello, World\n "
         fmt.Printf("%d %q\n", len(s), s)
         t := strings.TrimSpace(s)
         fmt.Printf("%d %q\n", len(t), t)}

    Output:

    16 "\t Hello, World\n "

    12 "Hello, World""

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Staven at Sep 5, 2015 at 6:54 am

    On Fri, Sep 04, 2015 at 02:56:22PM -0700, Stéphane phenetas wrote:
    I am trying to compare two string, but I guess one has a word wrap at the

    I see only one possibility, it is the "breadline" after the ".34"
    You mean... the newline?

    There's no way to say what the correct solution here is, since we
    don't know why this problem arises.

    If you're comparing strings, you should probably generate them in a way
    that allows them to be compared in the first place. If you're getting
    them from some external source, you might want to either filter out
    and use the IP addresses themselves (possibly with package regexp) or
    remove the newlines (possibly with strings.Replace(input, "\n", "", -1)).

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedSep 4, '15 at 9:56p
activeSep 5, '15 at 6:54a
posts3
users2
websitegolang.org

2 users in discussion

Stéphane phenetas: 2 posts Staven: 1 post

People

Translate

site design / logo © 2021 Grokbase