FAQ
Is there a way to find the number of bytes in a string without converting
it into a byte array?

i.e. I don't like the following:

len(byte[]("str"))




-Kowshik

--

Search Discussions

  • Evan Shaw at Sep 14, 2012 at 7:15 pm

    On Fri, Sep 14, 2012 at 2:07 PM, Kowshik Prakasam wrote:
    Is there a way to find the number of bytes in a string without converting it
    into a byte array?
    Try simply len(str). That gives you the number of bytes, not the
    number of Unicode code points.

    - Evan

    --
  • Jan Mercl at Sep 14, 2012 at 7:18 pm

    On Fri, Sep 14, 2012 at 9:07 PM, Kowshik Prakasam wrote:
    Is there a way to find the number of bytes in a string without converting it
    into a byte array?

    i.e. I don't like the following:

    len(byte[]("str"))
    Yes, use len(s): http://play.golang.org/p/gMDFeD1TkE

    -j

    --
  • DisposaBoy at Sep 14, 2012 at 7:21 pm

    On Friday, September 14, 2012 8:07:40 PM UTC+1, Kowshik Prakasam wrote:
    Is there a way to find the number of bytes in a string without converting
    it into a byte array?

    i.e. I don't like the following:

    len(byte[]("str"))




    -Kowshik
    len()


    --
  • Patrick Mylund Nielsen at Sep 14, 2012 at 7:23 pm
    len(s)

    http://golang.org/ref/spec#Length_and_capacity

    len(s) string type string length in bytes

    http://play.golang.org/p/BjhKaGSMJJ
    On Fri, Sep 14, 2012 at 9:07 PM, Kowshik Prakasam wrote:

    Is there a way to find the number of bytes in a string without converting
    it into a byte array?

    i.e. I don't like the following:

    len(byte[]("str"))




    -Kowshik

    --

    --

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedSep 14, '12 at 7:14p
activeSep 14, '12 at 7:23p
posts5
users5
websitegolang.org

People

Translate

site design / logo © 2023 Grokbase