FAQ
http://play.golang.org/p/-jOkcgYQUo

Why strings.Split("/","/") return slice with two empty elements?

--
Vasiliy Tolstov,
e-mail: v.tolstov@selfip.ru

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

  • Volker Dobler at Nov 12, 2015 at 10:07 am

    Am Donnerstag, 12. November 2015 10:54:49 UTC+1 schrieb Vasiliy Tolstov:
    http://play.golang.org/p/-jOkcgYQUo

    Why strings.Split("/","/") return slice with two empty elements?
    Because there are two empty strings left and right of the single seperator.

    V.

    --
    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.
  • Vasiliy Tolstov at Nov 12, 2015 at 10:52 am

    2015-11-12 13:07 GMT+03:00 Volker Dobler <dr.volker.dobler@gmail.com>:
    Because there are two empty strings left and right of the single seperator.

    Thanks, but on the left and on the right nothing present =).


    --
    Vasiliy Tolstov,
    e-mail: v.tolstov@selfip.ru

    --
    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.
  • Jérôme Champion at Nov 12, 2015 at 11:13 am
    And empty string is still something, there is no reason to treat it
    differently than an non empty string.
    Another way to look a it: http://play.golang.org/p/RQQu66FnmW

    Can I ask you what would you except it it weren't the case?


    Le jeudi 12 novembre 2015 11:52:48 UTC+1, Vasiliy Tolstov a écrit :
    2015-11-12 13:07 GMT+03:00 Volker Dobler <dr.volke...@gmail.com
    <javascript:>>:
    Because there are two empty strings left and right of the single
    seperator.


    Thanks, but on the left and on the right nothing present =).


    --
    Vasiliy Tolstov,
    e-mail: v.to...@selfip.ru <javascript:>
    --
    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.
  • Vasiliy Tolstov at Nov 12, 2015 at 11:25 am

    2015-11-12 14:12 GMT+03:00 Jérôme Champion <champioj@gmail.com>:
    And empty string is still something, there is no reason to treat it
    differently than an non empty string.
    Another way to look a it: http://play.golang.org/p/RQQu66FnmW

    Can I ask you what would you except it it weren't the case?

    After reading docs i think that i get empty []string{} slice =).


    --
    Vasiliy Tolstov,
    e-mail: v.tolstov@selfip.ru

    --
    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.
  • Mattn at Nov 12, 2015 at 11:26 am
    In Ruby or Perl spirit, they expect empty result.

    $ ruby -e 'p "/".split("/").size'


    However, I wonder they expect same with spriting empty string also.

    $ ruby -e 'p "".split("/").size'


    BTW, go return 1 because original empty string should be kept in the
    result. :)

    http://play.golang.org/p/PQAAC-4JnQ

    - mattn

    --
    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.
  • Vasiliy Tolstov at Nov 12, 2015 at 11:43 am

    2015-11-12 14:26 GMT+03:00 mattn <mattn.jp@gmail.com>:
    In Ruby or Perl spirit, they expect empty result.

    $ ruby -e 'p "/".split("/").size'


    However, I wonder they expect same with spriting empty string also.

    $ ruby -e 'p "".split("/").size'


    BTW, go return 1 because original empty string should be kept in the result.
    :)

    http://play.golang.org/p/PQAAC-4JnQ

    Nice =)

    --
    Vasiliy Tolstov,
    e-mail: v.tolstov@selfip.ru

    --
    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.
  • Milan P. Stanic at Nov 12, 2015 at 10:08 am

    On Thu, 2015-11-12 at 12:54, Vasiliy Tolstov wrote:
    http://play.golang.org/p/-jOkcgYQUo

    Why strings.Split("/","/") return slice with two empty elements?
    Split removes separator from original string. Put something around
    separator and try again. Example:
    strings.Split("a/b","/")

    --
    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
postedNov 12, '15 at 9:54a
activeNov 12, '15 at 11:43a
posts8
users5
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase