I have something like this:
and i would like to have something like this:
You should use Environment.NewLine as suggested by Jonesopolis.
See the documentation here, the caracters for the new line depend on the system you are targeting. Let the .NET framework know what a new line is.
You can use it like that
string str = String.Format("this text{0}is on three{0}lines", Environment.NewLine);
Or, if you're using the last version of C# (can be less readable if you have a lot of new lines) :
string newLine = Environment.NewLine;
string str = $"this text is{newLine}on three{newLine}lines";
Insert "\r\n" where ever you want to add line
"It's Felix Birthday\r\nIt's DesBirthday\r\nIt's Fffffffs Birthday!"
As stated before\r\n is a good use to insert new lines. Alternatively (and my personal choice) is to use Environment.NewLine which effectively does the same thing. However this is based on the Enviroment and therefore should be cross environment compatible (all-be-it no other WPF environment exists).
Something like
string message = string.Format("It's Felix Birthday{0}It's DesBirthday{0}It's Fffffffs Birthday!", Environment.NewLine);
Really this will just produce the same result as entering in the \r\n but also makes it a bit more readable.
MessageBox.Show("It's Felix Birthday\nIt's DesBirthday\nIt's Fffffffs Birthday!");
Just put "\n" where you want to new line
By using TextWrapping, you will be able to use multiline textbox.
TextWrapping="Wrap" MaxLines="2" Width="150"
Related
Ok, I'm racking my brains over this one. It's pretty simple though (I think).
I'm currently creating a text file as a comma separated string of values.
Later, I read in that file data and then use the .split function to split the data by commas.
I discovered that sometimes one of the description fields in the data conatins an embedded comma, which ends up throwing the split command off.
Is there any special character I could use that could pretty much guarantee wouldn't be in the data, or is there a better way to accomplish this? Thanks!
// Initial Load
fullString = fileName + "," + String.Join(",", fieldValues);
// Access later
String[] valuesArray = myString.Split(',');
Short answer, there's no "simple" way to do it using Split. The best you can hope for is to set the deliminator as something cooky that wouldn't ever get used (but even that's not a guarantee).
The simple method would be to used something like CsvHelper (get it through Nuget) or any of the other dozen or so packages that are designed for parsing CSV.
I have a database with almost 2000 code examples that I've collected over the last 10 years that I want to be able to access with a textarea field so I can copy and/or update easily. I'm trying to migrate from PHP to C# on a new domain, but I'm having problems getting it to display correctly.
This is how it looks currently: http://nunyabiz.freeiz.com/csharp/index.html
This is how it's supposed to look: http://nunyabiz.freeiz.com/csharp/index2.html
This is the code that I'm using to display it:
Code.Text = rs["Code"].ToString().Replace("\r\n", "\n");
The "\r\n" characters aren't getting recognized, so I'm guessing that I have to convert, encode or decode it, but I haven't had any luck trying to find something that will work. online.
you can try Environment.NewLine for Linebreaks Environment.Newline
strYourCode = string.Format("Name: {0} LineBreak {1}", yournameVariable, Environment.NewLine);
Try to figure out WHAT line breaks you have in your code samples - there are many variants including html tag br, and then change it to what you need (i think it is Environment.Newline)
And check that your Code control is Multiline
Give this a try .Replace("\r", "").Replace("\n", "<br/>");
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
I have a string for example like " :)text :)text:) :-) word :-( " i need append it in textbox(or somewhere else), with condition:
Instead of ':)' ,':-(', etc. need to call function which enter specific symbol
I thinck exists solution with Finite-state machine, but how implement it don't know. Waiting for advises.
update: " :)text :)text:) :-) word :-( " => when we meet ':)' wec all functions Smile(":)") and it display image on the textbox
update: i like idea with delegates and Regex.Replace. Can i when meet ':)' send to the delegate parameter ':)' and when meet ':(' other parameter.
update: Found solution with converting to char and comparing every symbol to ':)' if is equal call smile(':)')
You can use Regex.Replace with delegate where you can process matched input or you can simply use string.Replace method.
Updated:
you can do something like this:
string text = "aaa :) bbb :( ccc";
string replaced = Regex.Replace(text, #":\)|:\(", match => match.Value == ":)" ? "case1" : "case2");
replaced variable will have "aaa case1 bbb case2 ccc" value after execution.
It seems that you want to replace portions of the string with those symbols, right? No need to build that yourself, just use string.Replace. Something like this:
string text = " :)text :)text:) :-) word :-( ";
text = text.Replace(":)", "☺").Replace(":(", "☹"); // similar for others
textbox.Text += text;
Note that this is not the most efficient code ever produced, but if this is for something like a chat program, you'll probably never know the difference.
You could just create a dictionary with these specific characters as the key and pull the value.
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.