write the program to count the number of lines in a given string ...
s="hello,\n+ I am \n+"fine\n:
2.how we can display only last file

Recommended Answers

All 2 Replies

s="hello,\n+ I am \n+"fine\n: WHAT is that?!??

I think you mean something like :
string s = "hello,\n" + "I am \n" + "fine\n";

Use the Split function to accomplish what you want.

s="hello,\n+ I am \n+"fine\n: WHAT is that?!??

I think you mean something like :
string s = "hello,\n" + "I am \n" + "fine\n";

Use the Split function to accomplish what you want.

Usually a new line is "\r\n" so you will want to do what ddanbe said and use the split function on "\n". Windows lines are \r\n, UNIX lines are \n, so:

string text = "abc" + Environment.NewLine + "def";
      int lines = text.Split(new char[] { '\n' }).Length;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.