Android Question Multiple spaces in HTML [Solved]

Roger Daley

Well-Known Member
Licensed User
Longtime User
Hi All,

This is stretching the boundaries of being a B4X question but maybe someone can help.

I have a document written with LibreOffice Writer which needs to be read by the App user. The easiest way to do this is save the document as HTML and display it in a WebView.
Unfortunately when saved as HTML, multiple spaces and Tabs that I have used for formatting are trimmed.
My research said I can insert multiple spaces using ctrl+Spacebar. Not true. I have found no other option.

If anyone has a suggestion [a polite one] I would greatly appreciate it. Please remember I am not trying to build a web page, just display an existing document.

Regards Roger
 

Sandman

Expert
Licensed User
Longtime User
There are several different suggestions that might be relevant here, but it sure would help a lot if you explained more about your document, preferably attaching it to your post.
 
Upvote 0

Roger Daley

Well-Known Member
Licensed User
Longtime User
There are several different suggestions that might be relevant here, but it sure would help a lot if you explained more about your document, preferably attaching it to your post.
Sandman thanks for the reply.
I don't think the document is relevant. It is 3 pages of text, no pictures, no drawing objects, no special characters. Next week I may face the same problem with a totally different doc with 10 pages.
The core issue is how do I include multiple spaces without having them trimmed when Writer saves in HTML


Regards Roger.
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Since you're converting the original LibreOffice format to HTML, why instead not export to PDF and use a PDF viewer in your app?
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
If it is just a plain text in the file, you could try saving the document as a text file, then replacing multiple spaces when you load it into the app.

B4X:
' The loop is probably not be needed, try it and see.
Do While Text.Contains("  ")
    Text = Text.Replace("  ", "  ")
Loop

'And for Tabs
Text = Text.Replace(TAB,"    ") 'However many spaces you want per tab

The tabs are unlikely to align correctly unless you are using a fixed width font.

Edit: sorry forgot the semi colon.
 
Last edited:
Upvote 0

Roger Daley

Well-Known Member
Licensed User
Longtime User
Thanks for the replies but it seems I didn't make it clear. [My error]
Multiple spaces is bad style I initially found the problem when using 2 - 3 tabs then tried spaces as an alternative.

For example using 3 spaces before and after an arrow. [Lots of way to do this but this is just a demo of the problem.]
  1. SOME TEXT 3 SPACES ==> THEN AN ARROW, 3 SPACES AND MORE TEXT
  2. OTHER TEXT ==> SAME SPACING FRONT AND REAR OF ARROW
If I save this as HTML from Writer, close the Doc and then reopen it in Writer the triple spaces are trimmed to one space.
I'm sorry I didn't initially explain in this detail but I was trying to keep it brief and simple. [Catch 22]

SOLUTION:
1. What I needed is called Non Breaking Spaces. These are inserted by Shift+Ctrl+Space Bar.
2. The only other solution I found was to use Microsoft Office Word, the problem does not occur. This package is what I am trying to leave behind


Regards Roger
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
As mentioned in Post #4, the string " " is a non-breaking space character. That's what the "nb" in " " stands for.

So, before you save the HTML, just substitute all the soft spaces for hard spaces:

B4X:
Doc = "SOME TEXT   ==>   MORE TEXT"

Doc = Doc.Replace(" "," ")
Save "Doc.html"

Then the resulting HTML will be:

"SOME TEXT   ==>   MORE TEXT"

Which will display as follows in an HTML/Webview viewer:

"SOME TEXT ==> MORE TEXT"
 
Upvote 0

Roger Daley

Well-Known Member
Licensed User
Longtime User
As mentioned in Post #4, the string " " is a non-breaking space character. That's what the "nb" in " " stands for.

So, before you save the HTML, just substitute all the soft spaces for hard spaces:

B4X:
Doc = "SOME TEXT   ==>   MORE TEXT"

Doc = Doc.Replace(" "," ")
Save "Doc.html"

Then the resulting HTML will be:

"SOME TEXT   ==>   MORE TEXT"

Which will display as follows in an HTML/Webview viewer:

"SOME TEXT ==> MORE TEXT"

Thanks John,
Much clearer unfortunately:
When I save "SOME TEXT   ==>   MORE TEXT" as HTMl
Chrome displays it as "SOME TEXT   ==>   MORE TEXT"

Probably I did something wrong, I can easily stick to Shift+Ctrl+SpaceBar

Regards Roger
 
Upvote 0
Top