I am using FreeTextBox control
in asp.net.When I am getting its HtmlStrippedText in my code I am getting the String without HTML tags.Now how can I get the new line character from this String i.e. I want to Replace All the NewLine characters with Special Symbol "#".
Got the Solution:
Got the HtmlStrippedText in String str and then got replace it like this:
char enter=(char)111;
temp= str.Replace(enter+"", "\n");
If it is anything like the base ASP:TextBox, you can just grab the string from the text property and do something like
var test = txtYourControl.Text.Replace(Environment.NewLine, "#");
This will vary between browsers (perhaps even between the operating systems on which the browser is running). More on newline definitions here.
I have found the most reliable option to be to search and replace "\n" rather than Environment.NewLine which is "\r\n" in a Windows environment.
string text = this.txtField.Text.Replace("\n", "#");
HtmlStrippedText is used to get the plain text
You should use the text property of freetextbox control
u can remove new line using this code.
lblTitle.Text = txtFreetextbox.Text.Replace("<br>","#");
Click this link
http://freetextbox.com/docs/ftb3/html/P_FreeTextBoxControls_FreeTextBox_Text.htm
Related
I use htmlagilitypack.
This is part of my code to get innertext from single node.
var edit = outDocument.DocumentNode.SelectSingleNode("//textarea[#id='wpTextbox1']//text()");
String _edit;
_edit = edit.InnerText.ToString().Trim();
picture 1
When I write _edit to text file , All texts are bound(all enter characters removed).
picture 2
I want texts with enter characters.
How can I fix this?
Sorry for my bad English.
HTML text that you receive contains the character "\n" as newline. Meanwhile, Windows uses two symbols "\r\n" for this purpose. Therefore, the Notepad displays the text in this way.
You need to make the change:
string _edit = edit.InnerText.Replace("\n", Environment.NewLine);
I just want to replace a particular text with blank space in RDLC column.
I want to replace .aspx with "" in every string.
I tried writing
=Replace(Fields!AuditsUserActivity.Value, ".aspx", "")
it works for this kinda lines
Page Applicants.aspx viewed
but not for these kinda lines:
Data added in Inspectors.aspx
i.e. it removed .aspx from those lines in which .aspx appears in in-between but not for those in which .aspx appears at the end of string.
WHY ?
Update:
I used this but not working
=Replace(Fields!AuditsUserActivity.Value, "#"+".aspx", string.Empty)
Use this simple code:
string result = Regex.Replace("x.aspx", #"\b.aspx\b", string.Empty);
string inpString = "abcdeggggy.aspx";
string i = Regex.Replace(inpString ,#".aspx", "").Trim();
dont forget add using System.Text.RegularExpressions; namespace
Try this
string sResult= System.Text.RegularExpressions.Regex.Replace("abc.aspx", #".aspx", "");
Like many others have suggested, you should try using a regex expression. Perhaps try copying this exactly:
=System.Text.RegularExpressions.Regex.Replace(Fields!AuditsUserActivity.Value, ".aspx", "");
I have the following code and the regular expression I am currently using does not appear to be catching any url I enter in standard format (www.google.com) as when it is displayed in a listbox, the URL is still there. Does anyone know where I'm going wrong?
e1.MessageBody = txtMessage.Text;
Regex.Replace(e1.MessageBody, #"/((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+#)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+#)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%#.\w_]*)#?(?:[\w]*))?)/", ""string.Empty);
var msg = "ASD www.google.com EFIG";
msg = Regex.Replace(msg, #"((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+#)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+#)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%#.\w_]*)#?(?:[\w]*))?)", string.Empty);
C# doesn't use the regex identifiers (the leading/trailing /) and you had extra quotes " by the string.empty parameter.
I'm trying to write some text to a website using the System.Web.HttpUtility.HtmlEncode function in C#. The string parameter that I give to the function has some Environment.Newline's in it, but they are not written out on the website. Does anyone know why this is and how I can fix it. Thanks in advance.
Newline is written out as a physical line break so you will have to either wrap in a pre:
response.Write("<pre>" + HttpUtility.HtmlEncode(str) + "</pre>");
Or replace the new line with a BR AFTER you have HtmlEncoded (or it'll encode the BR as well):
response.Write(HttpUtility.HtmlEncode(str).Replace("\n", "<br />"));
Given its HTML NewLine characters do not display as whitespace. Try replacing your new line characters with <br/> elements.
I've been writing code for ASP.NET since the start, and today I encountered something I've never seen before. Typically I've looked for line breaks in C# (when posted in ASP.NET from a textarea, for example) by expecting "\r\n". Now I'm using the MVC framework, and the text coming over the wire from a textarea simply has "\n" for line breaks.
Is there something going on in old school TextBox controls that normalizes the line breaks? Since MVC just uses the form data as-is, is this normal? Would love to get some insight.
I have made observation that the actual line break sequence differs from browser to browser.
If you have a multiline textarea on a page and the page is submitted then:
IE returns "\r\n" to indicate newlines. FF returns "\n" in this case.
I tested it somewhere along the end of 2006, so it may be different now.
I do not believe it could have anything to do with WebForms vs. MVC. Both just process submitted input and return it to you as it is.
If you wish to somehow process and replace these characters it would make sense doing it in the long-to-short order:
string userText = form["Text"];
userText = userText.Replace ("\r\n", "<br/>").Replace ("\r", "<br/>");
\n is the line ending variant on *nix-style systems. \r\n is Windows-specific line-ending behaviour.
If you're checking for line-endings and expose your interface to non-Windows environments, be sure to check not only for \r\n but also for \n alone.
Fore more background, check out the Newline article at Wikipedia.
I am using Environment.NewLine :
string userText = form["Text"];
userText = userText.Replace (Environment.NewLine, "<br />")
Also take a look at #Haacked's post about some newline textarea quirks.