Line breaks in Multi-Line text?

Posted on
Mon Mar 20, 2017 5:08 am
autolog offline
Posts: 3988
Joined: Sep 10, 2013
Location: West Sussex, UK [GMT aka UTC]

Line breaks in Multi-Line text?

Is it possible to specify line breaks in multi-line text?

I am setting up text in a variable that I am trying to display i in a Multiline Text chart.
I have tried using \n but that just gets displayed in the chart.

Posted on
Mon Mar 20, 2017 5:58 am
DaveL17 offline
User avatar
Posts: 6742
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Line breaks in Multi-Line text?

Hi Jon - I'm using the textwrap() library which strips all '\n' new line characters in the source and then inserts them back it at 'n' characters (effectively making each line as close to the number of specified characters as possible). Let me play with the library a bit to see if there's a way to insert a control character into the text that will be honored by the library.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Mon Mar 20, 2017 1:32 pm
DaveL17 offline
User avatar
Posts: 6742
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Line breaks in Multi-Line text?

DaveL17 wrote:
Hi Jon - I'm using the textwrap() library which strips all '\n' new line characters in the source and then inserts them back it at 'n' characters (effectively making each line as close to the number of specified characters as possible). Let me play with the library a bit to see if there's a way to insert a control character into the text that will be honored by the library.

Turns out that there's no facility to deal with this directly, but I've ginned up a simple bit of code that may suffice. Please try to break it.

Code: Select all
import textwrap
new_text = ""
new_line = "\n\n"

old_text = u'Greetings\rProfessor\nFalken.[BREAK]Would you like to play a game?[BREAK]How about a nice game of chess?'

for item in old_text.split('[BREAK]'):
    new_text += str(textwrap.fill(item, 35)) + new_line
   
print new_text.rstrip("\n\n")

Code: Select all
================================================================================
Mar 20, 2017, 2:30:07 PM
untitled text 3
--------------------------------------------------------------------------------
Greetings Professor Falken.

Would you like to play a game?

How about a nice game of chess?

[ETA: fixes semi-bodged line in the script.]

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 3 guests