I know how to do it by using this code
poem['sleepy'] = 'busy'
What the above object type called? Is it an Array?
How can I assign the poem to the first line of the text in order to replace the word “sleepy” that is sitting on that specific line?
It’s not an array, it’s
String‘s[]=method. If you want to only replace on a certain line, you can split the poem string and get an array by using thesplitmethod:You could then make the replacement on the line you wish:
And then you can use
Array‘sjoinmethod to join theArrayinto aStringagain: