gpt4 book ai didi

arrays - 数组中键值对的字符串替换

转载 作者:数据小太阳 更新时间:2023-10-29 07:59:09 25 4
gpt4 key购买 nike

我正在尝试向数组中的一些键值数据发送消息,但遇到了困难。

这是我的数组中的内容:

data = [ "name=abc", "title=analyst", "group=IT", "id=123"]

我要翻译的映射:

mapping = { "name" => "EmployeeName", "title" => "JobTitle", "group" => "BusinessGroup", "id" => "EmployeeID"}

我追求的预期结果:

data = [ "EmployeeName=abc", "JobTitle=analyst", "BusinessGroup=IT", "EmployeeID=123"]

最佳答案

data.map {|s| s.sub /\w+/, mapping }
# => ["EmployeeName=abc", "JobTitle=analyst", "BusinessGroup=IT", "EmployeeID=123"]

关于arrays - 数组中键值对的字符串替换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33514272/

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