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')
print(result)
Output:
[[a,b,c],
[d,e,f]]
>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'))
prints:
[[a,b,c],
[d,e,f]]