Link to home
Start Free TrialLog in
Avatar of radupopescu777
radupopescu777

asked on

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?
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of radupopescu777
radupopescu777

ASKER

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?
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

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

Open in new window

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('~')
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..?



SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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 ':