q5

command
v0.0.0-...-afccd23 Latest Latest
Warning

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

Go to latest
Published: May 17, 2024 License: GPL-2.0 Imports: 3 Imported by: 0

README

字符串替换问题

问题描述

请编写一个方法,将字符串中的空格全部替换为“%20”。 假定该字符串有足够的空间存放新增的字符,并且知道字符串的真实长度(小于等于1000),同时保证字符串由【大小写的英文字母组成】。 给定一个string为原始的串,返回替换后的string。

解题思路

两个问题,第一个是只能是英文字母,第二个是替换空格。

源码参考 源码

源码解析

这里使用了golang内置方法unicode.IsLetter判断字符是否是字母,之后使用strings.Replace来替换空格。

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

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