当前位置:网站首页>Delete the last character of the string in golang
Delete the last character of the string in golang
2022-07-03 08:13:00 【Bel_ AMI classmate】
package main
import (
"fmt"
"strings"
)
func TrimSuffix(s, suffix string) string {
if strings.HasSuffix(s, suffix) {
s = s[:len(s)-len(suffix)]
}
return s
}
func main() {
s := "a string ++"
fmt.Println("s: ", s)
// Trim one trailing '+'.
s1 := s
if last := len(s1) - 1; last >= 0 && s1[last] == '+' {
s1 = s1[:last]
}
fmt.Println("s1:", s1)
// Trim all trailing '+'.
s2 := s
s2 = strings.TrimRight(s2, "+")
fmt.Println("s2:", s2)
// Trim suffix "+".
s3 := s
s3 = TrimSuffix(s3, "+")
fmt.Println("s3:", s3)
}
Output :
s: a string ++
s1: a string +
s2: a string
s3: a string +
边栏推荐
- Uniapp learning records
- Oracle insert single quotation mark
- [global product discovery 2] the first pure cloud augmented reality (AR) platform - Israel
- Get to know unity2 for the first time
- Wechat native applet cloud development learning record 01
- MXone Pro自适应2.0影视模板西瓜视频主题苹果cmsV10模板
- Unity performance optimization
- swagger文档配置
- Golang json格式和结构体相互转换
- How to establish rectangular coordinate system in space
猜你喜欢

Docker installs MySQL and successfully uses Navicat connection

Dotween plug-in
![[set theory] order relation (hastu example | divisive relation hastu | inclusive relation hastu | refinement relation hastu)](/img/de/1c75b5e7ed79aca47462de365428a7.jpg)
[set theory] order relation (hastu example | divisive relation hastu | inclusive relation hastu | refinement relation hastu)

Shader foundation 01

数据的存储

Easy touch plug-in

Lua framwrok framework starts

Wechat applet taro learning record

vcs import src < ros2. Repos failed

Pycharm remote ssh pyenv error: pydev debugger: warning: trying to add breakpoint to file that does
随机推荐
oracle 插入单引号
PostGIS space function
Docker installs MySQL and successfully uses Navicat connection
Three characteristics
Product creation and commercial realization of chat robot (according to La Ma Bang - Dr. Wang Jingjing - speech)
haproxy+keepalived搭建01
什麼是定義?什麼是聲明?它們有何區別?
One dimensional array two dimensional array (sort Max insert sort)
C#课程设计之员工信息管理系统
MaxCompute字符串分割函数-SPLIT_PART
L'installateur a été installé avec une erreur inattendue
register关键字
2021-10-19
Golang的range
Pulitzer Prize in the field of information graphics - malofiej Award
idea取消引用显示效果
Minimap plug-in
Flex flexible box layout
Golang 时间格式整理
Youyou1 of xlua knapsack system