Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | danilo00782 |
var q = ["Test1","Test2"]
q[0].erase(0,3)
print(q[0])
Output: Test1
Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | danilo00782 |
var q = ["Test1","Test2"]
q[0].erase(0,3)
print(q[0])
Output: Test1
Reply From: | Thomas Karcher |
q[0].erase(0,3)
gets the value of q[0], not the reference to it, so doing anything with this value will not affect the value stored in the array itself.
This should work:
temp_string = q[0]
temp_string.erase(0,3)
q[0] = temp_string
(Replaces the array element with the changed string)
Or even simpler:
q[0] = q[0].substr(4)
(Does everything in one step, but needs a method with a return value)