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
 

Brian Dean

Well-Known Member
Licensed User
Longtime User
The TAB characters will be there - try putting the output text into Windows Notepad and you should see them. If you are not seeing them in the email application or whatever it is you are using then that is where the problem is.

Of course, if you do not see TABs when you export the text to Notepad then the problem lies elsewhere, because TAB does work!
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
TAB is just an ascii character, chr(9). How it works depends on context. Within the IDE a TAB is equivalent to 4 spaces.
Inside a caption of a label it appears a one space. If TAB stops are defined (for example in a word document), then a tab would go to next tab stop.
The implementation of tab stops is extremely complex, requiring attention to font, kerning, etc. B4X does not have tab stops,
although BBCodeView has [Span][/Span] tags that can function as tab stops.
 
Upvote 0

BlueVision

Active Member
Licensed User
Longtime User
May work on windows, correct.
But also with a simple text-editor from on the phone itself there is no formatting visible. It's a pity.
Simple HTML could work. But this creates a huge overhead for a textfile with the size of 1500 Bytes, everything has to be declared precisely.
For putting simple plain text content in a formatted way into an email a "LOW-LEVEL PLAIN TEXT TO HTML-Encoder" would be a nice thing for defining things like bold, italic, underlining, tab, crlf and maybe the font color. Controlled by small and simple keywords within the sourcetext itself (like already done with "TAB" and "CRLF"...)

This could be a new challenge...
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
Can it be a solution?

test:
B4X:
    Dim sb As StringBuilder
    sb.Initialize
    sb.Append("This is the first substring:").Append(Chr(9)).Append("hello").Append(Chr(13))
    sb.Append("This is the second substring:").Append(Chr(9)).Append("hello").Append(Chr(13))
    sb.Append("This is yet the last substring:").Append(Chr(9)).Append("hello").Append(Chr(13))
    Log(sb.ToString)

NotePad++
1637689053752.png

word:
1637689169708.png


Note:
CRLF is NewLine Chr(10)
NOT return Char(13) and Newline Char(10)
 
Last edited:
Upvote 0

BlueVision

Active Member
Licensed User
Longtime User
Thank you guys, but I have to explain a little bit more...
I am collecting a subset of strings into a new string. With "filewrite" I put this final string into a file for testing. If I have a look into this file (I can do this on the mobile or when transferred to a windows-pc, the formatting remains intact (using notepad, editor, word). Everything ok.
But putting the content of this final string directly into the body of a simple email to make it directly visible when opening the email (sending with the phonelibrary) destroys all of the formatting.
Sure, I could put it as an attachment to the email, but I have to use fileprovider for doing this. This is a little bit over the top for such small content. When walking to the bakery on the corner for getting fresh bread, you are not dressing up yourself with a tuxedo before doing this...
It is only a small piece of formatted text...
So the question is better defined as: "How to put the assembled substring 1:1 without any changes to an email". This is probably a problem with transferring the content to the used mailing program. And this happens with other email-programs too.

Converted to HTML (with ms-word for testing), the filesize increases up to 500%. This makes 400% overhead (!!!) I have to program additionally into the text...

BBCode could solve this, but I am not sure if I can put the content of several variables during runtime into the file with BBCode. Could work if the BBCode-text gets interpreted as HTML and if the final recipients email-program can handle HTML directly...

Things could be so easy...
 
Upvote 0

BlueVision

Active Member
Licensed User
Longtime User
You are a Hero! I can't believe it! What's the difference?
I will try to rewrite it immediately using StringBuilder! Hope it works...
 
Upvote 0

BlueVision

Active Member
Licensed User
Longtime User
Then, bad news.
I changed "sb" to "Econt". So it is the same. Changed chr(13) to chr(10). This is CRLF. But still no "TABS".
 
Last edited:
Upvote 0

BlueVision

Active Member
Licensed User
Longtime User
large program...

B4X:
    Dim ECont As StringBuilder
    ECont.Initialize
    ECont.Append("Hallo Helpdesk,").Append(Chr(10))
    ECont.Append("bitte ordern:").Append(Chr(10)).Append(Chr(10))
    ECont.Append("Techniker:").Append(Chr(9)).Append(Chr(9)).Append(ACETCENumber.Text).Append(Chr(10))
    ECont.Append("Rückrufnummer:").Append(Chr(9)).Append(Chr(9)).Append(ACETPhoneCE.Text).Append(Chr(10))
    ECont.Append("Kundenname:").Append(Chr(9)).Append(Chr(9)).Append(ACETCustName.Text).Append(Chr(10))
    ECont.Append("AP des Kunden:").Append(Chr(9)).Append(Chr(9)).Append(ACETCustomer.Text).Append(Chr(10))
    ECont.ToString
    File.WriteString(SharedFolder,"Order.txt",ECont)
    PhoneData.HideKeyboard(Activity)
    Message.To.Add(ACETEmailCE.Text)
    Message.Subject = "CIP - PM-Call - Gebiet:"&SPArea.SelectedItem&"<//>SN:"&ACETSerial2.Text
    Message.Body = ECont.ToString
    StartActivity(Message.GetIntent)
    Sleep(0)
    Message.To.Clear
    Message.Subject = ""
    Message.Body = ""
    Message.Attachments.Clear

Around 4000 lines of code in total, this is huge. Ignore the FileWrite-Command, this is old-level, the "toString" is missing there. Putting

But within the extract you can see the relavant things, defining the stringbuilder, the chained append for the string.
When creating the email it opens with the intent above and I am able to send it.
chr(13) does not work. chr(10) gives me a CRLF and this works.
But chr(9), which is a TAB, is still ignored.
Screenshot_20211123-212136_Outlook.jpg


This is within the mail-application before sending. I marked the missing tabs. CRLF works. This is not exactly the place from the code above, but best visible.
Strange thing.
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
see:

B4X:
    Dim sb As StringBuilder
    sb.Initialize
    sb.Append("This is the first substring:").Append(Chr(9)).Append("hello").Append(Chr(13))
    sb.Append("This is the second substring:").Append(Chr(9)).Append("hello").Append(Chr(13))
    sb.Append("This is yet the last substring:").Append(Chr(9)).Append("hello").Append(Chr(13))
    Log(sb.ToString)
    
    File.WriteString(File.DirApp, "1.txt", sb.ToString)
 

Attachments

  • 1.txt
    109 bytes · Views: 154
Upvote 0
Top