golang bytes 包 详解

概况:

包字节实现了操作字节切片的函数。它类似于琴弦包的设施。

函数:

  1. func Compare(a, b []byte) int
  2. func Contains(b, subslice []byte) bool
  3. func ContainsAny(b []byte, chars string) bool
  4. func ContainsRune(b []byte, r rune) bool
  5. func Count(s, sep []byte) int
  6. func Equal(a, b []byte) bool
  7. func EqualFold(s, t []byte) bool
  8. func Fields(s []byte) [][]byte
  9. func FieldsFunc(s []byte, f func(rune) bool) [][]byte
  10. func HasPrefix(s, prefix []byte) bool
  11. func HasSuffix(s, suffix []byte) bool
  12. func Index(s, sep []byte) int
  13. func IndexAny(s []byte, chars string) int
  14. func IndexByte(b []byte, c byte) int
  15. func IndexFunc(s []byte, f func(r rune) bool) int
  16. func IndexRune(s []byte, r rune) int
  17. func Join(s [][]byte, sep []byte) []byte
  18. func LastIndex(s, sep []byte) int
  19. func LastIndexAny(s []byte, chars string) int
  20. func LastIndexByte(s []byte, c byte) int
  21. func LastIndexFunc(s []byte, f func(r rune) bool) int
  22. func Map(mapping func(r rune) rune, s []byte) []byte
  23. func Repeat(b []byte, count int) []byte
  24. func Replace(s, old, new []byte, n int) []byte
  25. func ReplaceAll(s, old, new []byte) []byte
  26. func Runes(s []byte) []rune
  27. func Split(s, sep []byte) [][]byte
  28. func SplitAfter(s, sep []byte) [][]byte
  29. func SplitAfterN(s, sep []byte, n int) [][]byte
  30. func SplitN(s, sep []byte, n int) [][]byte
  31. func Title(s []byte) []byte
  32. func ToLower(s []byte) []byte
  33. func ToLowerSpecial(c unicode.SpecialCase, s []byte) []byte
  34. func ToTitle(s []byte) []byte
  35. func ToTitleSpecial(c unicode.SpecialCase, s []byte) []byte
  36. func ToUpper(s []byte) []byte
  37. func ToUpperSpecial(c unicode.SpecialCase, s []byte) []byte
  38. func Trim(s []byte, cutset string) []byte
  39. func TrimFunc(s []byte, f func(r rune) bool) []byte
  40. func TrimLeft(s []byte, cutset string) []byte
  41. func TrimLeftFunc(s []byte, f func(r rune) bool) []byte
  42. func TrimPrefix(s, prefix []byte) []byte
  43. func TrimRight(s []byte, cutset string) []byte
  44. func TrimRightFunc(s []byte, f func(r rune) bool) []byte
  45. func TrimSpace(s []byte) []byte
  46. func TrimSuffix(s, suffix []byte) []byte
package main

import (
	"bytes"
	"fmt"
)
//bytes.Compare 比较返回一个按字典顺序比较两个字节切片的整数。如果a == b则结果为0,如果a <b则结果为-1,如果a> b则结果为+1。 nil参数等同于空切片
func main()  {
	var a,b []byte
	a = []byte{1}
	b = []byte{2}
	if bytes.Compare(a,b) < 0 {
		fmt.Println(" a < b\n")
	}

	a = []byte{2}
	b = []byte{2}
	if bytes.Compare(a,b) <= 0 {
		fmt.Println("a <= b\n")
	}

	a = []byte{3}
	b = []byte{2}
	if bytes.Compare(a,b) >= 0  {
		fmt.Println("a >= b \n")
	}

	if bytes.Equal(a,b) {
		fmt.Println(" a == b \n")
	}

	if !bytes.Equal(a,b) {
		fmt.Println(" a not equal b \n")
	}
}

  

package main

import (
   "bytes"
   "fmt"
)

//func Contains(b, subslice []byte) bool
//bytes.Constains 包含报告子切片是否在b内。
func main()  {
   var s1,s2 []byte
   s1 = []byte("abcfoo")
   s2 = []byte("abc")
   if bytes.Contains(s1,s2) {
      fmt.Println(" s1 constains s2 ")
   }

   fmt.Println(bytes.Contains([]byte("seafood"), []byte("foo")))
   fmt.Println(bytes.Contains([]byte("seafood"), []byte("bar")))
   fmt.Println(bytes.Contains([]byte("seafood"), []byte("")))
   fmt.Println(bytes.Contains([]byte(""), []byte("")))
}

  

原文地址:https://www.cnblogs.com/liujie-php/p/10674764.html

时间: 2024-08-30 02:23:20

golang bytes 包 详解的相关文章

Golang Context 包详解

Golang Context 包详解 0. 引言 在 Go 语言编写的服务器程序中,服务器通常要为每个 HTTP 请求创建一个 goroutine 以并发地处理业务.同时,这个 goroutine 也可能会创建更多的 goroutine 来访问数据库或者 RPC 服务. 当这个请求超时或者被终止的时候,需要优雅地退出所有衍生的 goroutine,并释放资源.因此,我们需要一种机制来通知衍生 goroutine 请求已被取消. 比如以下例子,sleepRandom_1 的结束就无法通知到 sle

Golang官方log包详解

Golang官方log包详解 以下全是代码, 详解在注释中, 请从头到尾看 // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Package log implements a simple logging package. I

转:android Support 兼容包详解

本文转自stormzhang的ANDROID SUPPORT兼容包详解 背景 来自于知乎上邀请回答的一个问题Android中AppCompat和Holo的一个问题?, 看来很多人还是对这些兼容包搞不清楚,那么干脆写篇博客吧. Support Library 我们都知道Android一些SDK比较分裂,为此google官方提供了Android Support Library package 系列的包来保证高版本sdk开发的向下兼容性, 所以你可能经常看到v4,v7,v13这些数字,首先我们就来理清

Spring——jar包详解(转)

Spring——jar包详解 org.springframework.aop ——Spring的面向切面编程,提供AOP(面向切面编程)的实现 org.springframework.asm——spring 2.5.6的时候需要asm jar包,spring3.0开始提供它自己独立的asm jar包 org.springframework.aspects——Spring提供的对AspectJ框架的整合 org.springframework.beans——所有应用都用到,包含访问配置文件,创建和

2.TCP_IP互联线缆_TCP_UDP报文抓包详解

TCP_IP互联线缆_TCP_UDP报文抓包详解 2.1网线标准 直通线 交叉线 异种设备互联使用直通线 同种设备互联使用交叉线 TCP和UDP 端口寻址 TCP数据格式 TCP三次握手 UDP数据格式 IP报头格式 ICMP报文格式 ARP协议 ARP报文格式

Spring中的jar包详解

下面给大家说说spring众多jar包的特点吧,无论对于初学spring的新手,还是spring高手,这篇文章都会给大家带来知识上的收获,如果你已经十分熟悉本文内容就当做一次温故知新吧.spring.jar 是包含有完整发布的单个jar包,spring.jar中除了spring-mock.jar里所包含的内容外其他所有jar包的内容,因为只有在研发环境下才会用到spring-mock.jar来进行辅助测试,正式应用系统中是用不得这些类的. 除了spring.jar文件,Spring还包括有其他1

iOS开发——使用Charles进行https网络抓包详解

我在前面两篇博客中<网络抓包工具Charles的介绍与使用><iOS开发--使用Charles进行http网络抓包详解>对Charles的http抓包进行了详细的讲解.今天我们来实现一下进行https的抓包,比http抓包稍微麻烦一点. (1)https初级的配置请参考<网络抓包工具Charles的介绍与使用>中的https配置部分. (2)由于目前iOS9更改了对于https网络的安全机制,所以还需要在iPhone上安装一个证书,安装方式如下: 在iPhone的Saf

ORACLE之UTL_FILE包详解

1 Utl_File包简介Oracle的UTL_FILE包用来实现对磁盘文件的I/O操作.(1)Oracle10g之前的版本需要指定utl_file包可以操作的目录.      方法:        1.alter system set utl_file_dir='e:/utl' scope=spfile;        2.在init.ora文件中,配置如下:UTL_FILE=E:/utl或者UTL_FILE_DIR=E:/utl;(2)Oracle10g之后的版本,只需要先创建一个路径即可.

Spring3.1 jar包详解和依赖关系

一.包的详解: Spring 3.1的jar包和以前的不一样,新版本的jar包把原来的包分解了,功能分工很明确: org.springframework.aop-3.1.1.RELEASE.jar ---- ---- spring面向切面编程,提供AOP(面向切面编程) org.springframework.asm-3.1.1.RELEASE.jar ---- ---- spring独立的asm程序 [spring2.5.6的时候需要asmJar 包,3.0开始提供他自己独立的asm.jar