Multi-line data in dashboard custom field of type textbox (CRLF vs LF)

I have an updatable dashboard that allows creating a label based on info on the order line (P/N, Order Num, Cust PO#, etc…). The text created is placed into a textbox, for any cleanup or tweaking before saving.

When the textbox does not have focus, the text appears fine. In the following, I clicked in the Read Only field of the Part Description (1), and the Prod Label text box(2) looks fine.

If I click in the Text box to make edits, the text appears to lose the new line characters and looks like:

I use the “\n” for making multi-line text string, like:

Desc = Desc + “\nActive Length: " + temp + " FT”;

Some of the textbox’s properties:

Multiline: TRUE
WordWrap: TRUE
ScrollBars: BOTH
EpiBinding: V_CK_Prod_Label_ML_1View.OrderDtl_ProdLabel_c

If I copy the text (when it looks like the 2nd pict above), and view with a Clipboard viewer, it shows the LF (0x0A) charcter is in the text.

image

If I place the cursor in the Prod Label Text box and hit the Enter key on my keyboard, then copy the text, the clipboard viewer shows a CR(0x0D) and a LF(0x0A) are inserted - instead of just a LF(0x0A).

Should my code that builds the text use \r\n instead?

Yes… actually you should use

Environment.NewLine 

Magic strings are not your friend :slight_smile:

1 Like

Any other “constants” I should use? Is
Environment.Tab
valid?

And every now and then a data filed ends up with a RS (hex 0x1E), a Record Seperator? in it. Exports that have the RS embedded in a field’s data, tend to get split when imported into programs like Excel. Any idea where they come from?

¿ ßut ╖ ¢ªn theÿ bè ƒün tô ùse ? ¥ep :slight_smile:

uʍop-ǝpᴉsdn sɔop ɹnoʎ uɐɔs ʇ,uop ʇsnɾ

1 Like

Iam trying to replace existing CRLFs with proper new lines. I wan tot do somethign like:

string myCom = MyComment.Text.Replace(char(10),Environment.NewLine );
myCom = myCom.Replace(char(13),Environment.NewLine );
MyComment.Text = myCom;

However, in this case, the compiler doesn’t like char or chr. Am I going about this the right way?
Thanks!
Nate

Is a cast (char)10 and (char)13
However replacing both of those is going to give you double breaks.
if you replace (char)10 with NewLine and (char)13 also with new line you’ll end up with 2 line breaks.

1 Like

Environment.NewLine is like a system constant, but can vary system to system, no?

There isn’t an ASCII or Unicode code for Environment.NewLine is there?

If Environment.NewLine in my environment is equal to “\r\n” (or 0x0D followed by 0x0A), and I use it like:

strMessage = "Hello World!" + Environment.NewLine;

And then store that in the DB, it’s just going to store the characters of

image

And now my data has hard coded control characters based on my system. Correct?

Environment.NewLine is based on your system yes but there’s a standard for Windows , Linux, Unix and Mac

So in a Windows Box Environment.NewLine is 13,10 (Carriage Return , Line Feed)

Linux is just 10 (Line Feed)
Mac is only 13 (Carriage Return)

Because everyone hats us. So in your case calvin it is stored as the Window Standard and if you run whatever in a Linux Box it may look funny.

now if we could get these folks into a room lock the door and don’t let them out until they’ve picked a winner… we’d be onto something.

1 Like

OH WOW… just make sure there are BLEACHERS so we can all watch the Cage Grudge Match of the Millenium!

What do you mean by this?

Not sure the syntax jose was going for, but "\x0A" should be equal to your char(10), and "\x0D" for your char(13)

myCom = myCom.Replace("\x0D",Environment.NewLine );

But as jose pointed out, NewLine is two characters. so replacing both (10 and 13) may give you double line breaks.

edit

now I see what Jose was doing.

myCom = myCom.Replace((char)13, Environment.NewLine );

That tells the compiler to treat 13 as a char. (char)65 is equal to A

Thank you! This compiles much better! Maybe I am on the wrong thread, but I am trying to have my text box show the line breaks when in edit mode. The problem is the user sees the line breaks, then clicks in the textbox and they all collapse into zero width characters.
Is there a way to show line breaks in a textbox in edit mode?

How did the text (with a line break) get in that field? Was it manually typed in, or created elsewhere?

I I think I may have started a thread on this myself

I believe the text was copied and pasted from a PDF. Taking a look with notepad++, I can see each line break is a CRLF.

Make sure the control’s multi-line property is true.

Multiline is set to true. Word wrap is on. and I also turned on the vertical scroll bars.

If you select those two lines in Notepad++, and paste them into the field, it shows as two lines. But as soon as you leave that field, the linebreak collapses?

This is interesting! If I copy and paste my comment text into n++, then copy and paste back out, the line breaks stay perfectly, even in edit mode! How can I reproduce this in code, so that my comment field automatically updates when I click in to edit it?

I have tried placing this bit of code into the comment box’s AfterEnterEditMode, BeforeEnterEditMode, GotFocus, and Enter events. (I understand this make double line breaks, but I can’t get it to do anything.)

		string myCom = MyComment.Text.Replace("/x0A",Environment.NewLine);				
		myCom = myCom.Replace("/x0D",Environment.NewLine);
		MyComment.Value = myCom; // also tried .Text

First off, it should be "\x0A" (notice the slash direction)

Here’s what I would do:
First, confirm what the UI does.

  1. Starting with a blank field type a line, with a return and a second line.
  2. Copy the fields contents to the clipboard.
  3. Use a program like Free Clipboard Viewer (https://freeclipboardviewer.com/) to inspect the contents of what you copied.

Does the selected data have both CR and LF in it? Like:

If it only stores one of them, then make an event on that field when it exits editing, to find any lone CR or LF, and replace with the pair.