Picking Up A Particular String

sivag

Member
Joined
Jul 10, 2007
Messages
15
Programming Experience
Beginner
Hi i need help regarding the following:


my goal is: Am reading a text file which has values delimited with '|'.
Now i need to search each line of text file for a specific string which i'll be receiving from user.If the searching string is found,i need to display a part of string from the line where i found the string.

I did the foll:

Am reading it with filestream reader & assigning those into a arraylist.

Using enumerator,i read each line from arraylist & temporarily assigning it to a variable.Then i used "contains" method to search the line for the specific string.

Problem is It works on all occurences of the string.For ex:if the string to be searched is CSC,it takes into account of all C,S,C's present in each line & displaying the other part of string from all lines wherever C,S,C's are found.It doesn't looking up for the particular combination "CSC"

Is there any other idea other than this or can this itself be made changes to make it work? PLZ HELP ME:)
 
You are mistaken about how String.Contains method works, but IndexOf and SubString is what you need:
VB.NET:
        Dim text As String = "the CSC string"
        text = text.Substring(text.IndexOf("CSC"))
And use List(Of String), not ArrayList.
 
Thanks for immediate reply but i want only the string "STRING" if i give CSC as search word.

The given code gives out "CSC STRING"
 
Add the length of the search string to the index found. You might want to check the return of IndexOf method first also, if it's -1 the search string wasn't found.
 
Forgot to mention

The line is delimited with pipe sym.In ex u provide, spaces where used.So do we need to mention the delimiting value
 
Why dont you post an example file up here, and use the BOLD button to highlight the bit you want to find, then we will be able to better understand what youre asking
 
No Source|abc|defgh|<b>ijklmn</b>|asd@ abc = '410'|aas
No Source|bc|defgh|<b>oop</b>|asd@ abc = '410'|aas


Am unable to use bold option.so mentioned the word to be displayed within <b> </b>.

Now if i give string abc,i should get "ijklmn" & not "ijklmn & oop"

Hope u can understand clearly.
 
No Source|abc|defgh|ijklmn|asd@ abc = '410'|aas
No Source|bc|defgh|oop|asd@ abc = '410'|aas

Now if i give string abc,i should get "ijklmn" & not "ijklmn & oop"

Hope u can understand clearly.

Sorry, i dont understand clearly

Are you saying that:

If the line contains "abc" then you want the text from the FOURTH set between the bars

VB.NET:
If line.Contains("abc") Then MsgBox( line.Split("|"c)([B]3[/B]) )
3 = FOURTH item (numberd from 0 as the FIRST)
 
Last edited:
NO i didn't get.I said if i use wat u've given i get one or more values from fourth set between bars.as both the lines contain "bc".Even though i give abc,it takes the foruth set value between bars from both the lines.That's my problem.

I want only the value from first line(No Source|abc|defgh|ijklmn|asd@ abc = '410'|aas) .

But i get from second line also.
so i get "ijklmn" as well as "oop"
 
Back
Top