If you are looking for a way to split a text into paragraphs with a particular string, then you have come to the right place. In this article, we will discuss how to use a simple method to split a text into paragraphs with a particular string. We will also discuss some of the advantages and disadvantages of this method. Finally, we will provide some examples of how to use this method in practice. By the end of this article, you should have a better understanding of how to split a text into paragraphs with a particular string.
You can use the split() method to split a text into paragraphs with a particular string.
Syntax:
string.split(separator, limit)
Example:
var text = “This is a paragraph. This is another paragraph.”;
var paragraphs = text.split(“. “, 2);
console.log(paragraphs);
// Output: [“This is a paragraph”, “This is another paragraph.”]
Try using RegEx.Split()
using this pattern:
(.*This is common text.*)
Well, giving priority to RegEx
over the string functions
is always leads to a performance overhead.
It would be great if you use: (UnTested but it will give you an idea)
string[] lines = IO.File.ReadAllLines("FilePath")
List<string> lst = new List<string>();
List<string> lstgroup = new List<string>();
int i=0;
foreach(string line in lines)
{
if(line.Tolower().contains("this is common text"))
{
if(i > 0)
{
lst.AddRange(lstgroup.ToArray());
// Print elements here
lstgroup.Clear();
}
else { i++; }
continue;
}
else
{
lstgroup.Add(line)
}
}
i = 0;
// Print elements here too