sách gpt4 ăn đã đi

chuỗi - golang - thay thế các ký tự chuỗi bằng số golang

In lại 作者:IT王子 更新时间:2023-10-29 02:32:35 37 4
mua khóa gpt4 giày nike

我正在尝试运行这段代码,用随机数替换字符串中的一个字符:

//Get the position between 0 and the length of the string-1 to insert a random number
position := rand.Intn(count - 1)
strings.Replace(RandomString,)

fmt.Println("Going to change the position number: ", position)
//Insert a random number between [0-9] in the position
RandomString = RandomString[:position] + string(rand.Intn(9)) + RandomString[position+1:]

执行时,输出为:

I was going to generate.. ljFsrPaUvmxZFFw
Going to change the position number: 2
Random string: lsrPaUvmxZFFw

谁能帮我把那个数字插入到所需的字符串位置?我没有找到任何重复的案例。

Cảm ơn trước.

câu trả lời hay nhất

[0, 9) 范围内没有可打印的字符。如果您想要一个 ascii 值,请从 48 ('0') 开始。您可能也想包括 9,所以使用 rand.Intn(10)

string('0' + rand.Intn(10))

关于string - golang - 用数字替换字符串字符 golang,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44142182/

37 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress