C# program to count the lines in a given string
All Answers
total answers (1)
Severity: 8192
Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated
Filename: libraries/Filtered_db.php
Line Number: 23
total answers (1)
Program:
The source code to count the lines in a given string is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.
Output:
Explanation:
Here, we created a Program class that contains two static methods CountLines() and Main().
In the CountLines() method, we find the "\n" characters to count lines in a specified string using the IndexOf() method. This method returns the count of lines to the Main() method.
In the Main() method, we created the string str initialized with "Mumbai Indians\nDelhi Capitals\nRajsthan Royals" and then count lines and print the count on the console screen.