Multiline text using st.text_area()

I want to know if there is a way to accept multiline text input and store it as a multiline string. Say this is my program:

import streamlit as st

string = st.text_area('Enter text', height=275)
if st.button('display'):
    st.write(string)

This program on execution, displays a textbox which allows me to enter multiline text input. something like:

line 1
line 2
line 3

but when I use the write function, the output is:
line 1 line 2 line 3

Is it possible to store and display the input as a different lines?

Hi @Siddhesh-Agarwal, welcome to the Streamlit community!

You can achieve this by using splitlines:

 import streamlit as st


t = st.text_area("Enter multiline text")

if t is not None:
    textsplit = t.splitlines()

    for x in textsplit:
        st.write(x)

Best,
Randy

1 Like