Click here to Skip to main content
15,885,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all,
i m trying to contruct messages to be sent to users.
befroe adding the signature i want to insert a newline.
i m using the below code.
MIDL
Message = Message + Environment.NewLine;
                 Message = Message.Replace("#Signature#",
 obju.Signature);


but the messages are sent without a newline.

can anyone please help?
thanks.
Posted

Since this is ASP.NET, try replacing Environment.NewLine with "<br />"
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 1-Jun-11 15:50pm    
You are right, but how do you know where in HTML is is inserted? It could be inserted in a textarea, then it will need a type separator. Next time keep it in mind. :-) I voted 5 for now.

Please see my general answer. OP needs to know how to insert correctly, first of all.
--SA
You insert incorrectly. The only reasonable way is:

C#
string format = "My first line;{0}My second line";

//...

string separatedForTextBox = string.Format(format, System.Environment.NewLine);
string separatedForHtml = string.Format(format, "<br />");


Please keep in mind: string is immutable, so "+" is not efficient. (Do I have to explain why?)

—SA
 
Share this answer
 
v2
Comments
Hemant__Sharma 2-Jun-11 2:35am    
There is no technical problem here it's the logic which is not giving proper result.

when you said incorrect you should have explained what is happening in his case. see my answer.

The only reasonable way... if you are talking about performance, yes please explain "why". And when you give any theory please stick to current question's scenario only.

It may be safe to say string.Format is good to use and has 100s of feature but does it fit in current scenario? I always believe performance improvement solution depends on the scenario so if solution A can improve performance in Scenario 1 it doesn't gurantee it will improve performance in Scenario 2

thanks,
Hemant
Sergey Alexandrovich Kryukov 2-Jun-11 2:45am    
I will explain why when OP asks me. For experts it must be obvious.

"And when you give any theory please stick to current question's scenario only." - No. Why should I?

"I always believe performance improvement solution depends on the scenario". You absolutely right, but in case of format it always beats "+" or at least provides the same speed. As it's also more readable, it's better.

--SA
The problem is you are adding new line at the end of the message so
if your message is

Message = "abcd #signature#";


the first code line Message = Message + Environment.NewLine; will result in

Message = "abcd #signature# + NewLine character"


and the second line
MIDL
Message = Message.Replace("#Signature#",
 obju.Signature);

will replace the signature before new line character hence end result will be:

Message = "abcd TheSignature + NewLine character"

Solution:
Modify above code like this:
MIDL
//Message = Message + Environment.NewLine;
                 Message = Message.Replace("#Signature#",
 Environment.NewLine + obju.Signature);


Hope it will help.

Thanks,
hemant
 
Share this answer
 
You need to use the break instead of the NewLine:

MIDL
Message = Message + "";
 Message = Message.Replace("#Signature#",
 obju.Signature);
 
Share this answer
 
v2
Comments
Hemant__Sharma 1-Jun-11 7:34am    
No this is not right answer not even close. See my answer for the problem what is happening in OP's case. He implemented the same logic in his javascript code i.e. adding new line character before signature.

-Hemant

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900