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?
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Why dont you just replace the text with the new line like this
string s;
s = Replace(TxtNews.Text.ToString(), "@#%x", Environment.NewLine);
Sorry like this
string s;
s = TxtNews.Text.Replace("@#%x", Environment.NewLine);
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('~')
txtNews.Text.Split('~')
ASKER
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..?
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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 ':
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 ':
ASKER
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?