• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1027
  • Last Modified:

newline in varchar

Hello,
I am trying to put in a nvarchar field in my database the content from a textbox.
I can't figure out how to insert the newline.
My idea was to put something like "@#%x" in the text when i want a new line and then:

string s,ss;
s = TxtNews.Text.ToString();
ss = s.Split(""@#%x");
s= ss(0) + Environment.NewLine + ss(1);

But i have more then 1 newline, and not the same number. I don't know how to count how many times "@#%x" because string method Contains returns a bool, not an number. Can someone show me another way to do it?
0
radupopescu777
Asked:
radupopescu777
  • 2
  • 2
  • 2
  • +2
3 Solutions
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
ss = s.Split(""@#%x");
number_of_xxx = s.Length - 1
0
 
dhananjayadCommented:
Just allow the user to enter a new line into the textarea by pressing the enter key. When you read the content of the textarea
txtNews.Text.Split("\n");
0
 
radupopescu777Author Commented:
String Var1,Var2,Var3;
                Var1 = TxtDetalii.Text.ToString();
                Var2 = Var1.Split("#@#");


When i do this is says:
Error      1      The best overloaded method match for 'string.Split(params char[])' has some invalid arguments. Do you know why?
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
sunithnairCommented:
Why dont you just replace the text with the new line like this
string s;
s = Replace(TxtNews.Text.ToString(), "@#%x", Environment.NewLine);

Open in new window

0
 
sunithnairCommented:
Sorry like this
string s;
s = TxtNews.Text.Replace("@#%x", Environment.NewLine);

Open in new window

0
 
dhananjayadCommented:
Parameters for Split are a character array. So what you need to do is, use a special character like '~' for the new line and then:

txtNews.Text.Split('~')
0
 
radupopescu777Author Commented:
If i use the replace function with Environment.NewLine it just inserts another /n in the text.

And if i use:
 string Var1;              
 Var1 = Var1.Split('~');
It gives me: Error      1      Cannot implicitly convert type 'string[]' to 'string.

And if i try:
 String Var1;
 String[] Var2;
 Var2 = Var1.Split('~');
It gives me: Error      1      Use of unassigned local variable 'Var1'

Help..?



0
 
BlomholmCommented:
I assume you are going to display the text from the database somewhere on your site and you want there to be paragraphs. Not just one big chunk of text ?
Could do it like this:

Literal lit = new Literal();
lit.Text = YourStringFromDb.Replace("\n", "<br />");

Open in new window

0
 
BlomholmCommented:
If your TextArea is set to TextMode="Multiline"
then it will containt '\n' characters where the user hit enter.
So if you insert the content of : yourTextArea.Text into the db, you'll get the newlines characters inserted in db as ' \n ':
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

  • 2
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now