Android Question Use of TAB and CRLF for string formatting...

BlueVision

Active Member
Licensed User
Longtime User
Probably another "not seeing the forest for the trees" question...
It is a nasty problem when combining some substrings together for putting the whole string finally then to an email.

B4X:
    ECont = ECont & "This is the first substring:" & TAB & Label1.Text & CRLF
    ECont = ECont & "This is the second substring:" & TAB & Label2.Text & CRLF
    ECont = ECont & "This is yet the last substring:" & TAB & Label3.Text & CRLF

Why is TAB not really working in this code in opposite to CRLF? Is there a need for defining TAB before using it? Could not find an answer within the forum.
So far my workaround is to determine the length of the substrings and filling the "missing" space with a calculated amount of spaces.
This works well for monospaced fonts. The use of TAB would be much better and easier in this case, because:
Imagine you are using the variable ECont later for filling an Email with text. I am sure, the email-program (whatever it is) is not using a monospaced font.
Any ideas are very welcome.

Cheers BV
 

BlueVision

Active Member
Licensed User
Longtime User
It's ok. It is just a very simple way of submitting some text content.
I replaced the tab-space with a calculated amount of underscore-signs ( _ ), this looks ok, so far. Perhaps I can substitue it with something else. Think there is no other easy way to get rid of this problem.

The application is installed on the phone, outlook too. So the easiest way is drop the string to outlook using the phone-library.
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
Since the default email msg format is HTML, why not convert your message to html yourself (Not Word which creates a massive document).
B4X:
Dim Msg As String = $"
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>

<p style="white-space:pre">text in element 1234&#9;more text</p>
<p style="white-space:pre">text in element 123&#9;&#9;more text</p>
<p style="white-space:pre">text in element 12&#9;&#9;more text</p>
<p style="white-space:pre">text in element 1&#9;&#9;more text</p>
<p style="white-space:pre">text in element&#9;&#9;more text</p>

</body>
</html>

"$

Note that this renders the tab as 4 spaces but lines up the "more text" part. You need to compute how many tabs you need.
 
Upvote 0

BlueVision

Active Member
Licensed User
Longtime User
Like this. Honestly I have absolutely no idea about HTML. Maybe I can try to create it step by step with using StringBuilder. Try and Error. It's a total of 20 to 30 lines, it's absolutely worth trying it! And the result is visible immediately, when the prepared mail pop's up.

4 spaces is absolutely enough for separating.
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
If you use stringbuilder...

1. Single quotes work just as well in above html.
2.html doesn't care about lines. So..


B4X:
Dim Msg As String = $"
<!DOCTYPE html><html><head></head><body>

<p style='white-space:pre'>text in element 1234&#9;more text</p>
<p style='white-space:pre'>text in element 123&#9;&#9;more text</p>
<p style='white-space:pre'>text in element 12&#9;&#9;more text</p>
<p style='white-space:pre'>text in element 1&#9;&#9;more text</p>
<p style='white-space:pre'>text in element&#9;&#9;more text</p>

</body></html>
"$
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
If you use stringbuilder...

1. Single quotes work just as well in above html.
2.html doesn't care about lines. So..


B4X:
Dim Msg As String = $"
<!DOCTYPE html><html><head></head><body>

<p style='white-space:pre'>text in element 1234&#9;more text</p>
<p style='white-space:pre'>text in element 123&#9;&#9;more text</p>
<p style='white-space:pre'>text in element 12&#9;&#9;more text</p>
<p style='white-space:pre'>text in element 1&#9;&#9;more text</p>
<p style='white-space:pre'>text in element&#9;&#9;more text</p>

</body></html>
"$
see:
 
Upvote 0

BlueVision

Active Member
Licensed User
Longtime User
Are you sure HTML works when using the PhoneLibrary for sending the intent to the email program?
I am afraid this is more a solution for SMTP together with the net-lib. I am sure that sending an HTML-code via the PhoneLib as an intent to the email-program results in putting the HTML-code into the mails body as plain text, not recognized as a "script" for displaying embedded content HTML-like...
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
my last comment to this post.

Read.
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
Did you set the Mime type to text/html as opposed to text/plain as according to @oparra link?
I can't tell from my experience, but there must be members who have done this.
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
See Email html (email.GetHtmlIntent)

Search:

read:
Input: getType() is the MIME type of the data being sent. get*Extra can have either a EXTRA_TEXT or EXTRA_STREAM field, containing the data to be sent. If using EXTRA_TEXT, the MIME type should be "text/plain"; otherwise it should be the MIME type of the data in EXTRA_STREAM. Use */* if the MIME type is unknown (this will only allow senders that can handle generic data streams). If using EXTRA_TEXT, you can also optionally supply EXTRA_HTML_TEXT for clients to retrieve your text with HTML formatting.
 
Last edited:
Upvote 0

BlueVision

Active Member
Licensed User
Longtime User
These simple lines should work for sending Html-intent or did I miss something?

B4X:
    Message.To.Add(your.mail@somewhere.com)
    Message.Subject = "HTML-Test"
    Message.Body = "<b>Hello</b>"
    StartActivity(Message.GetHtmlIntent)

I get a selection, which mail-program to use, choose it, mail opens with filled message.to and message.subject. but message.body remains blank, no plain text, no Html, nothing. Looks like no acceptance of Html to me.
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
This thread is now quite different from your title.

If you want help from other members, I suggest that you create another thread
and make your request more specific to sending html texts from your phone default app.
It really has nothing to do with TAB and CRLF in B4X.
 
Upvote 0

BlueVision

Active Member
Licensed User
Longtime User
You are right. Let's finish this.
It is strange and the problems source is the email-app on the phone. Outlook on the mobile for instance reacts HTML-like, when you send a plain text-intent from outside to the email-app, outlook is reducing TAB and multiple SPACES to one single SPACE. On the other hand it also blocks completely HTML-content from outside. So there is no chance to succeed.

So what is the workaround? It is simple. Just prevent using multiple SPACES and TABS. Instead of SPACES or TABS you can use the ASCII U+200A for instance (minimum space). You can chain these characters endlessly without deletion by outlook and the email is correctly formatted.
The problem with this is, if you are not able to select a monospaced font, formatting is a thing of multiple tries. But it works very good when there is only one "TAB"-position per line and the characters left from that "TAB"-position are always the same (a never changing description or something like this). The characters to the right of that virtual "TAB"-position (the end of the "multiple minimum spaces") starting in the same "row" then.
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
Like this. Honestly I have absolutely no idea about HTML.
Amateur tip: Use a BASIC HTML editor and format up some text just the way you want it then steal the source and insert your text where you want it. Outlook and Word add a HUGE amount of stems and seeds that you don't need.
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Longtime User
I also have a few more tips:
  • An email message is something more than just a simple HTML code. Every email client (especially Microsoft's) suffers from “special behavior”. So what is correct HTML code will not always displayed correctly by every email client.

  • Therefore, choose an email template that is made to work well on as many email clients as possible. Place that HTML code between $""$ characters and add the results with variable(s) via ${}.

  • Maybe not pure in HTML5 teaching, but that way you can also put the results in a table in which you insert the results as a variable.
 
Upvote 0
Top