babis95
babis95

Reputation: 622

Python, Convert white spaces to invisible ASCII character

A quick question. I have no idea how to google for an answer.

I have a python program for taking input from users and generating string output. I then use this string variables to populate text boxes on other software (Illustrator). The string is made out of: number + '%' + text, e.g.

'50% Cool', '25% Alright', '25% Decent'.

These three elements are imputed into one Text Box (next to one another), and as it is with text boxes if one line does not fit the whole text, the text is moved down to another line as soon as it finds a white space ' '. Like So:

50% Cool 25% Alright 25%
Decent

I need to keep this feature in (Where text gets moved down to a lower line if it does not fit) but I need it to move the whole element and not split it. Like So:

50% Cool 25% Alright
25% Decent

The only way I can think of to stop this from happening; is to use some sort of invisible ASCII code which connects each element together (while still retaining human visible white spaces).

Does anyone know of such ASCII connector that could be used?

Upvotes: 0

Views: 1623

Answers (1)

Ken Kinder
Ken Kinder

Reputation: 13140

So, understand first of all that what you're asking about is encoding specific. In ASCII/ANSI encoding (or Latin1), a non-breaking space can either be character 160 or character 255. (See this discussion for details.) Eg:

non_breaking_space = ord(160)

HOWEVER, that's for encoded ASCII binary strings. Assuming you're using Python 3 (which you should consider if you're not), your strings are all Unicode strings, not encoded binary strings.

And this also begs the question of how you plan on getting these strings into Illustrator. Does the user copy and paste them? Are they encoded into a file? That will affect how you want to transmit a non-breaking space.

Assuming you're using Python 3 and not worrying about encoding, this is what you want:

'Alright\u002025%'

\u0020 inserts a Unicode non-breaking space.

Upvotes: 1

Related Questions