账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    golang中的 string(line)源码实现在哪里
    62
    0

    问题:这行代码

    str := string(line)

    line是 []byte 类型, 我想查看string函数的实现, 在哪里可以看到?

    点击string函数 跳转到

    // string is the set of all strings of 8-bit bytes, conventionally but not
    // necessarily representing UTF-8-encoded text. A string may be empty, but
    // not nil. Values of string type are immutable.
    type string string
    

    找不到string函数

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 东洲鱼 普通会员 1楼

      在Go语言中,string(line)函数是在fmt包中的Stringer接口中的方法。这个方法可以将一个字符串转换为整数类型。

      这个函数的源码如下:

      go func string(line string) int { n := len(line) return n }

      在这个函数中,len(line)返回字符串的长度,然后将这个长度作为整数返回。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部