convert

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 11, 2018 License: Apache-2.0 Imports: 2 Imported by: 0

README

Type Convert

Documentation

Overview

Package convert is collections method to convert types.

Now we supported types: - string <-> bytes

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bytes2String

func Bytes2String(bs []byte) string

Bytes2String converts byte slice to a string without memory allocation. See https://groups.google.com/forum/#!msg/Golang-Nuts/ENgbUzYvCuU/90yGx7GUAgAJ .

Note it may break if string and/or slice header will change in the future go versions.

Example
package main

import (
	"fmt"
	"github.com/jiusanzhou/knife-go/convert"
)

func main() {
	fmt.Println(convert.Bytes2String([]byte{59}))
}
Output:

func String2Bytes

func String2Bytes(str string) []byte

String2Bytes converts string to a byte slice without memory allocation.

Note it may break if string and/or slice header will change in the future go versions.

Example
package main

import (
	"fmt"
	"github.com/jiusanzhou/knife-go/convert"
)

func main() {
	fmt.Println(convert.String2Bytes("Hello knife-go!"))
}
Output:

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL