gpt4 book ai didi

用 "&"替换字符中的最后一个逗号

转载 作者:行者123 更新时间:2023-12-03 23:16:39 26 4
gpt4 key购买 nike

我有许多不同的字符,它们具有以下结构:

# Example
x <- "char1, char2, char3"

我想用“&”删除该字符的最后一个逗号,即所需的输出应如下所示:
# Desired output
"char1, char2 & char3"

如何用“&”替换字符的最后一个逗号?

最佳答案

一种选择是 stri_replace_last来自 stringi

library(stringi)
stri_replace_last(x, fixed = ',', ' &')
#[1] "char1, char2 & char3"

关于用 "&"替换字符中的最后一个逗号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54577567/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com