Highlighted
Respected Contributor.
Respected Contributor.
875 views

Removing Carriage Return from Rich TextBox In WinForm

Jump to solution

I have a rich multi-line text box with the string “Testing field. ENTER”.  If I press the enter key (carriage return) before the word “ENTER”, it adds a “/n”,  which I believe stands for new line or end of line, to the text property of the rich text box which then looks like follows: "Testing Field. \nENTER."

When I move the text string from my rich text box into a string variable, it moves the “\n” which give me problems when I attempt to do data manipulation with the string variable.  I cannot remove the “\n” programmatically in the code because it is invisible to the code. I can only see it when a view the text property of my rich text box during runtime.

I should also mention that after pressing the enter key before the word “ENTER”, it configures the ‘Lines’ property of the rich text box as follows:

Lines

  [0]  “Testing Field.”

  [1] “ENTER”

 

I want to be able to move both lines [0] and [1] as a single string into a string variable and without the “\n”.

0 Likes
1 Solution

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

Re: Removing Carriage Return from Rich TextBox In WinForm

Jump to solution

The \n means newline character but if you view it in hex what it is actually embedding is a X"0A" or the LineFeed character.

Right-click on the variable while debugging and click on Hexadecimal display and you will see:

richTextBox1 = {Text = x"54657374696E67206669656C642E200A454E544552"}

You could replace all occurrences of the X"0A" by spaces with the following:

               move richTextBox1::Text to mystring
               inspect mystring replacing all X"0A" by " "

View solution in original post

0 Likes
4 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

Re: Removing Carriage Return from Rich TextBox In WinForm

Jump to solution

The \n means newline character but if you view it in hex what it is actually embedding is a X"0A" or the LineFeed character.

Right-click on the variable while debugging and click on Hexadecimal display and you will see:

richTextBox1 = {Text = x"54657374696E67206669656C642E200A454E544552"}

You could replace all occurrences of the X"0A" by spaces with the following:

               move richTextBox1::Text to mystring
               inspect mystring replacing all X"0A" by " "

View solution in original post

0 Likes
Highlighted
Respected Contributor.
Respected Contributor.

Re: Removing Carriage Return from Rich TextBox In WinForm

Jump to solution
This worked, thank you!
0 Likes
Highlighted
Honored Contributor.
Honored Contributor.

Re: Removing Carriage Return from Rich TextBox In WinForm

Jump to solution

Just as a reminder ... searching the forum to see if the question has already been answered sometimes works.  For example:

https://community.microfocus.com/t5/Visual-COBOL-Forum/String-handling-carriage-return-line-feed-new-line-0d0a/m-p/1735063#M7722

 

0 Likes
Highlighted
Respected Contributor.
Respected Contributor.

Re: Removing Carriage Return from Rich TextBox In WinForm

Jump to solution
I will keep that in mind, thank you. But I should mention that it is sometimes difficult finding the topic of inquiry in the forum given that the subject name may be worded in a way that is different than the one that is being searched.
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.