2

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' */
1
  • You want to extract the following "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" into a new string? Commented Jan 30, 2012 at 13:30

2 Answers 2

1
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);
Sign up to request clarification or add additional context in comments.

Comments

0

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);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.