You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何实现将字符串中的起始单引号替换为{、结束单引号替换为}?

嘿,这就帮你搞定格式转换的需求!

转换后的目标内容

[ { 'Architecture & Planning' } { 'Banking' } { 'Financial Services' } { 'Financial Services' } { 'Internet' } { 'Hospitality' } { 'Marketing and Advertising' } ]

手动操作步骤(适合单次处理)

如果只是手动改这一段的话,两步就能完成:

  1. 把每一个开头的单引号'替换成{ '
  2. 把每一个结尾的单引号'替换成' },同时删掉原数组里的逗号分隔符就行

代码自动转换方案(适合批量处理)

要是你需要处理大量这类数组,可以用Python脚本一键转换:

original = ['Architecture & Planning', 'Banking', 'Financial Services', 'Financial Services', 'Internet', 'Hospitality', 'Marketing and Advertising']
# 把每个元素包装成 { 'xxx' } 的格式
formatted_elements = [f"{{ '{item}' }}" for item in original]
# 拼接成最终的字符串格式
final_result = f"[ {' '.join(formatted_elements)} ]"
print(final_result)

运行这段代码就能直接得到你想要的输出格式咯~

内容的提问来源于stack exchange,提问作者poonam

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.12 04:01:46