Reputation: 2417
I have this text :
<Parag1>Data-tier applications can be used to work with existing databases, or they can be used to implement new projects and releases.
To get started, it is recommended that you create data-tier applications from existing systems by registering each production database as a data-tier application.</Parag1>
<Parag2>Then, users can extract each database to produce a DAC package and send the packages to the development team.</Parag2>
<Parag3>From there on, developers use Visual Studio to author data-tier changes, package them appropriately, and forward the updated DAC packages to production.</Parag3>
<Pagag4>In turn, DBAs can upgrade the production applications using automatic methods and tools that are provided by the data-tier application framework.</Parag4>
I need to extract the text from 'with existing databases' in paragraph 1 to 'each database to produce' in paragraph 2.
How can I get this result in c# with the following inputs:
start paragraph : p1
Start character index : 43
/* index of w in 'with' */
Finish paragraph : p2
Finish character index : 47
/* index of e in 'produce' */
Upvotes: 2
Views: 912
Reputation: 26936
int i = text.IndexOf("with existing databases");
int i2 = text.IndexOf("each database to produce");
int l = "each database to produce".Length;
string substring = text.Substring(i, i2 - i + l);
Upvotes: 1
Reputation: 14700
Do you need to preserve the paragraph separation, or do you just need the text? If the paragraphs are irrelevant, I would load this XML snippet into an XmlDocument object, merge the texts into a single string, and then just use normal string manipulation to extract.
var snippet = //your text here.
var rawXml = "<text>" + snippet + "</text>"; // Wrap to make valid XML.
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(rawXml);
var mergedText = xmlDoc.InnerText;
int start = mergedText.IndexOf(startMarker);
int end = mergedText.IndexOf(endMarker) - start;
mergedText.Substring(start, end);
Upvotes: 0