Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我知道如何使用此代码来做到这一点
poem['sleepy'] = 'busy'
上面的对象类型叫什么?它是一个数组吗?我如何将这首诗分配到文本的第一行,以替换位于该特定行的单词“sleepy”?
它不是一个数组,它是String's[]=方法。如果你只想替换某一行,你可以拆分诗歌字符串并使用以下split方法得到一个数组:
String
[]=
split
lines = poem.split("\n")
然后,您可以在您希望的线路上进行替换:
lines[3]["sleepy"] = "busy"
然后你可以使用Array'sjoin方法再次加入Array到 a中String:
Array
join
poem = lines.join("\n")