manipulating strings, search text

Posted by alhambraeidos on Stack Overflow See other posts from Stack Overflow or by alhambraeidos
Published on 2010-06-04T14:50:49Z Indexed on 2010/06/05 10:02 UTC
Read the original article Hit count: 333

Filed under:
|
|

Hi all, I try explain my issue:

note 1: I have only strings, not files, ONLY strings.

I have a string like this (NOTE: I include line numbers for better explain)

The line separator is \r\n (CRLF)

string allText = 

1 Lorem ipsum Lorem ipsum

2 == START 001partXXX.sql ==

3 Lorem ipsum TEXT Lorem ipsum

4 == END 001partXXX.sql ==

5 Lorem ipsum TEXT Lorem ipsum

6 == START 002partzzz.sql ==

7 Lorem ipsum TEXT Lorem ipsum

8 == END 002partzzz.sql ==

I have contents strings like this:

string contents1 =
== START 001partXXX.sql ==

Lorem ipsum TEXT Lorem ipsum

== END 001partXXX.sql ==

the other content string:

string contents2 =

== START 002partzzz.sql ==

Lorem ipsum TEXT Lorem ipsum

== END 002partzzz.sql ==

Then,

allText.IndexOf(contents1) != -1

allText.IndexOf(contents2) != -1

I need function thats receive 3 parameters: allText, Contents, and text to find in contents, and it returns the line number of Text To Find in AllText

For example,

input: allText, contents2, "TEXT"

ouput = line number 7

Another sample,

input: allText, contents1, "TEXT"

ouput = line number 3

Another sample,

input: allText, contents1, "TEXT NOT FOUND"

ouput = line number -1

How can I implement this function ?? any help very useful for me,

Thanks in advanced.

© Stack Overflow or respective owner

Related posts about c#

Related posts about search