Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
I have a string variable like:-

string str="Hello Mr.XXX,Welcome to My Company,You Have successfully Login,Regards,xxx";

I want To break it like:-
Hello Mr,XXX,
Welcome to My Company
You Have successfully Login
Regards
xxx

And I want to put it inside a string.

means String xyz=

I want To break it like:-
Hello Mr,XXX,
Welcome to My Company
You Have successfully Login
Regards
xxx


If any solution then please help me.


thanks.
Posted
Comments
saini arun 31-Mar-12 6:29am    
Split the string by comma, this will give you an array which will have each line you want as its items.
Run a foreach loop on the array and generate the target string by appending new line character or <br /> in each iteration.

This is the logic, you need to convert it into code.

There are a number of ways to do this.
You can use string.split on the new line character or use a regular expression.
 
Share this answer
 
Hi,

If you are doing the same from server side, i think better way should be.

1. Put a div tag in the web page

ASP.NET
<div  runat="server" id="divMessage"></div>


2. Assign the value from from server side ; replace the comma character with as shown below.

divMessage.InnerHtml = Convert.ToString("Hello Mr.XXX,Welcome to My Company,You Have successfully Login,Regards,xxx").Replace(",", "</br>");


So no need to split and it should work.

Hope it works.
 
Share this answer
 
v3
Use
\n
to break a string.
 
Share this answer
 
Comments
Estys 31-Mar-12 6:44am    
That's bad, when possible use Environment.NewLine. Anyway, a single "\n" is a unix-style newline, on windows platforms it should be "\r\n".
nagendrathecoder 31-Mar-12 6:46am    
Yeah you are right. :)

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