FAQ
Hi,

Can not understand why this happens but I would think that strings.Trim()
is character based, not regex based. But it seem if I want to remove
"?format=Entity" and my string just ends on "a", it removes 'a', which
should not happen I guess? Do I understand the function call incorrectly?
Or is just a bug in the api

Here is a play example:
https://play.golang.org/p/NgQiakn_cT

While if it ends up "b", nothing is removed as exepcted:
https://play.golang.org/p/2uwyl_i_IY

Thanks

--
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

  • Julian Phillips at Mar 30, 2016 at 3:37 pm

    On 30/03/2016 16:23, Timothy Dewin wrote:
    Hi,

    Can not understand why this happens but I would think that
    strings.Trim()
    is character based, not regex based. But it seem if I want to remove
    "?format=Entity" and my string just ends on "a", it removes 'a', which
    should not happen I guess? Do I understand the function call
    incorrectly?
    It sounds like you want TrimSuffix which will remove a given string from
    the end of the input, not Trim which removes characters (actually
    Unicode code points) from both the beginning and the end.

    Trim will remove any character you specify from the beginning or end of
    the string, until it encounters a character not in your cutset. It
    doesn't care about the order or characters within the cutset.
    Or is just a bug in the api

    Here is a play example:
    https://play.golang.org/p/NgQiakn_cT

    While if it ends up "b", nothing is removed as exepcted:
    https://play.golang.org/p/2uwyl_i_IY

    Thanks
    --
    Julian

    --
    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.
  • Will Norris at Mar 30, 2016 at 4:11 pm
    Or use strings.TrimSuffix <https://golang.org/pkg/strings/#TrimSuffix>,
    which sounds more like what is desired here.
    On Wed, Mar 30, 2016 at 8:37 AM, Julian Phillips wrote:
    On 30/03/2016 16:23, Timothy Dewin wrote:

    Hi,

    Can not understand why this happens but I would think that strings.Trim()
    is character based, not regex based. But it seem if I want to remove
    "?format=Entity" and my string just ends on "a", it removes 'a', which
    should not happen I guess? Do I understand the function call incorrectly?
    It sounds like you want TrimSuffix which will remove a given string from
    the end of the input, not Trim which removes characters (actually Unicode
    code points) from both the beginning and the end.

    Trim will remove any character you specify from the beginning or end of
    the string, until it encounters a character not in your cutset. It doesn't
    care about the order or characters within the cutset.

    Or is just a bug in the api
    Here is a play example:
    https://play.golang.org/p/NgQiakn_cT

    While if it ends up "b", nothing is removed as exepcted:
    https://play.golang.org/p/2uwyl_i_IY

    Thanks
    --
    Julian


    --
    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.
    --
    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.
  • Timothy Dewin at Mar 30, 2016 at 5:07 pm
    Thanks, figured it out as well. Tried to delete the post but apparently it
    didnt work :)

    Thanks anyway for the reply
    On Wednesday, March 30, 2016 at 5:38:21 PM UTC+2, Julian Phillips wrote:
    On 30/03/2016 16:23, Timothy Dewin wrote:
    Hi,

    Can not understand why this happens but I would think that
    strings.Trim()
    is character based, not regex based. But it seem if I want to remove
    "?format=Entity" and my string just ends on "a", it removes 'a', which
    should not happen I guess? Do I understand the function call
    incorrectly?
    It sounds like you want TrimSuffix which will remove a given string from
    the end of the input, not Trim which removes characters (actually
    Unicode code points) from both the beginning and the end.

    Trim will remove any character you specify from the beginning or end of
    the string, until it encounters a character not in your cutset. It
    doesn't care about the order or characters within the cutset.
    Or is just a bug in the api

    Here is a play example:
    https://play.golang.org/p/NgQiakn_cT

    While if it ends up "b", nothing is removed as exepcted:
    https://play.golang.org/p/2uwyl_i_IY

    Thanks
    --
    Julian
    --
    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
postedMar 30, '16 at 3:23p
activeMar 30, '16 at 5:07p
posts4
users3
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase