I am sending a mail with text attachment from my VB6 application.
I am using Content-Transfer-Encoding:7bit in header for text attachment.
Problem is that after downloading file from mail,new lines are not displayed properly in NOTEPAD.
But other applications such as notepad++,wordpad are properly displaying the new lines as they are in the original text file.
Where i am going wrong?
My first guess would be that you are ending your lines with just a new-line, instead of a carriage-return/new-line pair. The windows standard is that you need cr/nl at the end of each line, while Linux puts only nl. Notepad chokes on lines that end with just nl, but Wordpad figures it out.
Related
I receive emails where the body contains raw data (long csv lines) from an external application. I want to store this data in a text file. However, when I store it (File->Save As->txt) Outlook automatically inserts line breaks at the position specified in the Outlook Options "Automatically wrap text at character". This cannot be set to anything higher than 132, and the remove extra line breaks does nothing when saving data.
Is there any way I can fix this or do I have to use another mail client than Outlook?
Through the GUI it may not be possible but one solution to this problem
is to use something other than the MailItem.SaveAs command in vba (macro code). https://forums.slipstick.com/threads/84759-line-breaks-added-to-text-file/
I have an issue with getting the contents of a tkinter text box. If I paste information into it from Excel (for example), it always adds an empty line at the bottom. I would like to remove that line automatically. This is what I use to get the contents:
contents = inputText.get(1.0, "end-1c")
for line in contents.split("\n"):
line = line.strip()
I initially added a '[:-1]' on the end of that, which works, but only on text that is pasted into the text box. If you type text in manually, then obviously there's no trailing '\n' on the end, so it ends up removing the last character that was typed. Not good!
How can I get it to remove (or ignore) the trailing empty lines? The 'line = line.strip()' in the code further down seems to have no effect.
Thanks, Chris.
Your problem isn't with getting the text, your problem is that pasting seems to add more than you expect. To get text, regardless of how it ended up in the widget, you should use .get("1.0", "end-1c"). There is simply no way to know at the time you are getting the contents of the widget if any extra newlines came from the user directly or from a paste operation. To tkinter, text is text no matter how it was entered.
The only solution is to adjust the paste binding, and even that is problematic because I don't think tkinter has any way of knowing if the clipboard contents are from excel, or from some other source.
If all you really want is to ignore all trailing blank lines, call strip() on the data before calling split("\n")
Textbox was always inserts a blank line at the end. The problem was compounded when editing textbox and yet another blank line was inserted. However during edit you could remove blank lines so you can't use "end-1c" all the time.
The trick was to remove 1 or more extra blank lines after editing:
# Rebuild lyrics from textbox
self.work_lyrics_score = \
self.lyrics_score_box.get('1.0', tk.END)
while self.work_lyrics_score.endswith('\n\n'):
# Drop last blank line which textbox automatically inserts.
# User may have manually deleted during edit so don't always assume
self.work_lyrics_score = self.work_lyrics_score[:-1]
Note however this is with Linux. For Windows you might need something like:
while self.work_lyrics_score.endswith('\n\r\n\r'):
# Drop last blank line which textbox automatically inserts.
# User may have manually deleted during edit so don't always assume
self.work_lyrics_score = self.work_lyrics_score[:-2]
Or whatever the the control code is for DOS/Windows LF/CR (Line Feed / Carriage Return) typewriter days style is.
I am trying to set up a (USB) Motorola Symbol DS6708 barcode scanner to scan QR code encoded with some contact information onto a text file.
When scanning in a barcode, the expected text is displayed on in the text file. When it is finished reading it in all the text is selected and deleted.
If it hit ctr+z, the text is undeleted and displayed in the file.
The desired result is in this format:
Name
Title
Company
Phone
ect
I'm not really sure where to start with debugging this. I am assuming that there is some characters being read in at the end that doing the equivalent of ctrl+a and delete.
EDIT
I tried scanning using the 123Scan2 from Motorolo, and this was the result:
<STX> <STX> <STX>318315647 <ETX> <LF>NAME<ETX> <ETX>LNAME<ETX> <LF>TITLE <ETX>
<LF>COMPANY <ETX>
<LF>ADDRESS <ETX> <LF>ADDRESS <ETX> <LF>CITY<ETX>, <ETX>ST<ETX> <ETX>12345<ETX> <LF>USA <ETX>
<LF>PHONE <ETX> <LF>PHONE <ETX>
<LF>EMAIL <ETX> <LF> <LF> <LF> <LF> <LF> <SUB> <CR>
EDIT
I attempted to set console application with C# and read in the input with Console.Read() or Console.ReadLine(), but the input actually caused the application to stop running, and then the input text was written into the text of the Program.cs file on Visual Studio.
The simple console app:
class Program
{
static void Main(string[] args)
{
System.Diagnostics.Debug.WriteLine("start");
int result;
while ((result = Console.Read()) != 0)
{
Console.WriteLine("{0} = {1}", result, (char)result);
}
}
}
I'm not really sure where to start with debugging this. I am assuming
that there is some characters being read in at the end that doing the
equivalent of ctrl+a and delete.
I attempted to set console application with C# and read in the input
with Console.Read() or Console.ReadLine(), but the input actually
caused the application to stop running, and then the input text was
written into the text of the class on Visual Studio.
I would bet that the data contain an EOF char (Ctrl+Z). All text devices (like console I/O) use this as an end signal, and it is still supported in modern OSes, although little known these days. And of course it is documented.
When it is finished reading it in all the text is selected and
deleted. If it hit ctr+z, the text is undeleted and displayed in the
file.
You probably want to say, that the text is shown in the editor, and selected/deleted from the editor. A file can't hardly display anything on it's own, it just contains something. By the way, the fact that EOF is Ctrl+Z and your editor's undo is also Ctrl+Z is pure coincidence.
As you don't show any code, it's hard to say anything about it. I'd probably do a Read() loop and store everything useful I get in a suitable place, for example in a file :-) This data are then to be processed in a second step.
PS: This related question may also be helpful.
I haven't played with barcode scanners for a while but this sounds to me that either the barcode you are scanning contains the control codes to do Ctrl-A and Del or that the scanner is programmed in that way.
To the host PC a barcode scanner basically appears like a keyboard. If you can type it, the barcode scanner can deliver it, including all Ctrl / Shift / Alt shortcuts.
If you have the scanner from new you should have a sheet of barcodes that allow you to program it up and affect its behavior. Have a look for a full reset barcode and see if that improves things.
You might want to try their sdk downloaded here. tell me if it still deletes the file in the textbox of the form.
If it isn't deleted, it might be better to add an export to a text file button.
My question is related to this topic How to copy and paste code without rich text formatting? except its from the opposite viewpoint: I'm creating a document from PowerPoint in which I have code snippets in text boxes. I want to make the document as simple as possible by making the code snippet text boxes easy to copy and paste the code into a terminal to run without editing anything. However, the way I have it right now is that when I copy and paste it keeps the formatting and I have to go though letter by letter to erase the end of line symbols. How should I format this in PowerPoint?
You can get rid of most formatting by copy/pasting from PPT to Notepad and then copy/pasting from there to your terminal program, or if the latter has a Paste Special command, you should be able to paste as plain text, which'd get rid of formatting.
Line/Paragraph breaks are another matter. If the end of line symbols are the only formatting problem when you've pasted the text into a terminal (emulator program, I assume), it sounds as though the terminal's using CR or LF as a line ending, whereas PPT's using CR/LF pairs. It might only be necessary to reconfigure the terminal software to use CR/LF.
It's worth a look at this page on my site, where I explain what line and paragraph ending characters are used by different versions of PowerPoint in different situations.
Paragraph endings and line breaks
http://www.pptfaq.com/FAQ00992_Paragraph_endings_and_line_breaks.htm
Sorry, my mistake was not realizing that PowerPoint auto formats hyphens and quotation marks to make them stylized, and the terminal was not recognizing the symbols. All I did was type in a quotation mark/hyphen then copying that before I pressed the space bar after it to save the original formatting.
I've created a Rich Edit control (1.0) from MFC as below:
m_hRichEditWnd = ::CreateWindow(_T("RichEdit"), csWindowName, ES_MULTILINE|ES_READONLY, 0, 0, 200, 200, NULL, 0, 0, 0);
I've read text into that control from a file. The file is a multipage .txt document with ascii control characters for page breaks. When I print from the Rich Edit control, I do not get the page breaks. They are printed out as characters. Is there any way to get those page breaks?
I'm printing out from the control using methods similar to those described here http://msdn.microsoft.com/en-us/library/windows/desktop/bb787875(v=vs.85).aspx
So something I left out was that I wasn't actually printing out to a physical printer but to a .ps file. That .ps file was then getting converted by ghost script to a pdf which did not register the page breaks. I believe this is due to the fact that the edit control does not actually SHOW page breaks inside it - and the way the print command works is almost like a graphic blit to a print device. The page break isn't "on screen" so it doesn't make it to the .ps file. That's a theory.
The only solution I found was to parse the information going into the CRichEditControl for form feed characters. Load up all characters up to the form feed character, print that to the file, then use the EndPage() function to manually force the form feed. Continue on in that way until there are not more form feed characters. Then make sure you print out any remaining characters after the last form feed.