stringx

package
v0.0.0-...-bd22ede Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ByteSliceToString

func ByteSliceToString(b []byte) string

ByteSlice2String convert []byte to string without copy. notice: this function is not safe, the bytes passed to String must not be modified afterwards.

func StringToSliceByte

func StringToSliceByte(s string) []byte

StringToSliceByte is like StringToSliceByteOld,but it's more simple. notice: this function is not safe, if you want to write the []byte, you should copy it.

func StringToSliceByteOld

func StringToSliceByteOld(s string) []byte

StringToSliceByteOld if we directly use []byte(string) to convert a string to []byte, in fact, there will be a copy. The reason is that Go's design is that string is immutable, but []byte is mutable, so when converting this way, a copy will be made. If you don't want to copy the conversion, you need to use unsafe. The meaning of this code is to get the address of the string first, and then assemble a slice byte header. In this way, you can convert string to []byte without copying data, but you need to pay attention that the []byte generated in this way is not writable, otherwise the behavior is undefined.

Types

This section is empty.

Jump to

Keyboard shortcuts

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