Adding a Substring to a String without knowing the position

I want to add a char(newline) to a String by specifiying the location with a Substring.

Is that possible in Python or Java?

Here’s how I imagine it,

Newline is added to the String at the position between two arrays '],':

str = [[a,b,c], [d,e,f]]

result = addString(str, '],', '\n')



>Solution :

Python-wise, your str variable uses a reserved keyword and missing the quotes.

you can do it in python as below:

mystr = "[[a,b,c], [d,e,f]]"       
print(mystr.replace('],', '],\n'))



Leave a Reply