Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Sir,
I'm Trying in text line some part of that line come on the new line.It can be possible?

e.g.
that's my input line:-
FORM OF APPLICATION FOR PURCHASE OF KISAN VIKAS PATRA (BY INVESTMENT THROUGH AGENTS) Serial No……………………

I want the output as follows:-
FORM OF APPLICATION FOR PURCHASE OF KISAN VIKAS PATRA (BY INVESTMENT THROUGH AGENTS)
Serial No……………………

Serial No…………………… sub string come on new line..
How?
Posted
Updated 13-Mar-15 2:21am
v2
Comments
CHill60 13-Mar-15 8:18am    
Is the text hard-coded and where are you trying to display it?

Try this..

C#
string  oldString = "FORM OF APPLICATION FOR PURCHASE OF KISAN VIKAS PATRA (BY INVESTMENT THROUGH AGENTS) Serial No……………………";
string newString = oldString.Replace(")", ")\n");


or
C#
string text = "FORM OF APPLICATION FOR PURCHASE OF KISAN VIKAS PATRA (BY INVESTMENT THROUGH AGENTS) Serial No……………………";
text = text.Replace(")", ")" + System.Environment.NewLine);
 
Share this answer
 
Comments
Member 11466475 13-Mar-15 8:47am    
Thank u so mutch for the help...

This is my input file:-
a) In the name(s)……………………….and ………………………. b) In the case of minor, his date of birth……………………
encashable by the minor’s parent/guardian Shri/Smt ………. c) Agent’s name …………………………….. d) Certificate of Authority No……………………..

I want output as follow:-
a) In the name(s)……………………….and ……………………….
b) In the case of minor, his date of birth……………………encashable by the minor’s parent/guardian Shri/Smt ……….
c) Agent’s name ……………………………..
d) Certificate of Authority No……………………..
Sergey Alexandrovich Kryukov 13-Mar-15 9:16am    
Well... not quite. Please see also Solution 2.
—SA
Please see Solution 1, but…

Those new lines depend on where you want to output it. Most usually, ASP.NET generates HTML, then the end-of-line should be <br/>.

Besides, what happens if you write System.Environment.NewLine for new line? This is the absolutely correct way to get new line for… the system where the code is running. In case of ASP.NET, this is the platform of the host running the HTTP server, server-side host. If the result is delivered to some client, the result depends on the client's platform and software. Even though these days the end-of-line problem is massively solved, this platform difference remains, as a monument if humans' short vision, stubbornness and poor collaborative skills. Please see:
http://en.wikipedia.org/wiki/Newline[^].

—SA
 
Share this answer
 
// yourText contains your text data
yourText = yourText.Replace("\r\n", "<br />");
 
Share this answer
 
v2
Further to solutions 1 and 2 but in light of the sample data you subsequently posted, the following function will handle a continuous stream of text which is to be separated into clauses based on "a)", "b)", "c)" etc up to "z)"
C#
private string NewLinesBetweenClauses(string inputString, string nl)
{
    // Generate a list of separators a), b), c) ... z)
    var separators = Enumerable.Range(0, 26).Select(x => ((char)(x + 'a')).ToString() + ') ').ToArray();

    // The "(s)" will upset our separators if the number of clauses is 14 or more
    // So remove it temporarily
    var tempString = inputString.Replace("(s)", "%s%");

    // Split the string based on the clauses
    var clauses = tempString.Split(separators, StringSplitOptions.RemoveEmptyEntries);

    // Build up the output
    var newString = new StringBuilder("");
    for (var i = 0; i < clauses.Length; i++)
    {
        //Put the a), b) etc back into the text (removed by the split)
        newString.Append(separators[i]);
        newString.Append(clauses[i].Replace("%s%", "(s)"));
        newString.Append(nl);
    }

    return newString.ToString();
}

Key points are handling any "(s)" in the text that shouldn't be split with a new-line the way that "s) " should.
Note that any phrases in brackets (for example) will cause issues
If you don't want to use Linq to generate the separators then the following will also do it
C#
string[] separators = new string[26];
for (int i = 0; i < 26; i++)
    separators[i] = ((char)(i + 'a')).ToString() + ') ';

The parameter nl is passed in so that it can be used with HTML newline or winforms style newlines. e.g.
C#
var inputString = "a) In the name(s)……………………….and ………………………. b) In the case of minor, his date of birth……………………encashable by the minor’s parent/guardian Shri/Smt ………. c) Agent’s name …………………………….. d) Certificate of Authority No……………………..";
Console.WriteLine(NewLinesBetweenClauses2(inputString, "<br/>"));
Console.WriteLine(NewLinesBetweenClauses2(inputString, Environment.NewLine));
 
Share this answer
 

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