MichaelS,
I've tried that already, and I tried "\r" alone too.
I also tried to put 13 (ascii code).
They all produce the same result (strange characters).
Main Topics
Browse All TopicsHello Experts,
I have a code that copies several lines of text to the
clipboard. The lines are separated by carriage-return
line-feed characters.
I use this line of code:
SetClipboardData(CF_TEXT, hBuffer);
where hBuffer represents a string that looks something
like this:
Text1\r\nText2\r\nText3\0
When pasting this text to another program, the result
SHOULD be:
Text1
Text2
Text3
But instead I get this:
Text1<strange characters>Text2<strange characters>Text3
Is there another way to put carriage-return line-feed
characters on the clipboard, beside \r\n ?
Is other words - Is there another way to force a new line
in the copied text?
Thanx
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
alexcohn,
When I paste the text to Notepad I get one line like this:
Text1(strange characters)Text2(strange characters)Text3
When I paste the text to Microsoft Word I get the result I want:
Text1
Text2
Text3
but this happens also if I put a space character (' ') between the lines instead of carriage-return line-feed.
I want the result to be the same wherever I paste the text to.
It has something to do with the clipboard, not the program I paste to.
For example, the text I just pasted to Word, when I copy it AS IS to the clipboard and then paste it to Notepad, it gives the right results. Meaning, Word puts on the clipboard some kind of common character that is interpreted as a new line, regardless of the program that gets the text.
Well the problem is solved. Somehow...
It turns out that when I pass the \r and the \n separately (instead of \r\n at once), it works ok.
I don't know what's the cause of this strange behavior, maybe a bug in my development tools, or a bug in my program somewhere (and I don't know which is worse...).
Rob, I ran a test like you suggested, and while I was doing that the above idea came to me. So I'm giving you the points and I thank you very much.
motile
The string to be passed to the clipboard is built part by part from different places. When a new line is detected the \r\n is added. When that didn't work I added \r alone, then added \n. And it worked...
Seems stupid, ha?
Well, guess what? I really did find a bug in the program, something to do with another thread that accidentally influenced the building of the string (too complicated to explain). So it turns out this all damn thing was about a silly mistake.
Yet another ordinary week in the life of a programmer... :-)
Once again thanx, Rob, you really did help.
Business Accounts
Answer for Membership
by: MichaelSPosted on 2001-03-11 at 01:18:13ID: 5917871
Try to use only "\n" instead of "\r\n"