Replace string in multiline text

Good morning I have problem when i go to use string.replace() in my script where string is a multiline text.

I don’t receive any error , script arrive to the end, but replace don’t be do it.

here a piece of code :

text = event.source.parent.getComponent(‘lblprintBase’).text

value = event.source.parent.getComponent('ptProd').QR
text.replace('@QR', value)

value = event.source.parent.getComponent('ptProd').Line1
text.replace("@LINE1", value)

value = event.source.parent.getComponent('ptProd').Line2
text.replace("@LINE2", value)

value = event.source.parent.getComponent('ptProd').Line3
text.replace("@LINE3", value)

value = event.source.parent.getComponent('ptProd').Line4
text.replace("@LINE4", value)

value = event.source.parent.getComponent('ptProd').Line5
text.replace("@LINE5", value)

event.source.parent.getComponent('lblprintMod').text= text

Some ideas ?


See some documentation:

Python string method replace() returns a copy of the string…

So you need to reassign your text:

text = text.replace("@QR", value)
1 Like