how can we find the spacific text in the text file?
how can we find the spacific text in the text file
for eg
ABC12345
ABC48587
ABC75891
acctually i want to get the 5 numbers after abc
thanks
how can we find the spacific text in the text file
for eg
ABC12345
ABC48587
ABC75891
acctually i want to get the 5 numbers after abc
thanks
you could read through each line and check the text on the fly:
Dim theStreamReader as new System.IO.StreamReader("filename.txt")
while theStreamReader.Peak() > -1
dim theCurrentLine as string = theStreamReader.ReadLine()
'current line in file is stored in the variable above, now do whatever checking it is you would like to
end while
of course performance will decrease if you have a big file, since you are iterating through each line.
to get specific text, you could use Regex (regular expression) to do a pattern matching technique which is great.
You could also use another nasty way, using string parsing etc... so if I had the text:
ABC12345
and wanted to get everything after ABC, and I know that I have ABC in the text:
Dim theString as string = "ABC12345"
Dim theTextIWant as string = theString.SubString(theString.IndexOf("ABC"))
would get me everything after "ABC"
does this help?
thanks a lot
acctually i have problem to get the 5 numbers after ABC. for eg
fkj;dsfjajdfjd;fljdkfjfjABC12345ffjkfdjfkdjkjdkfjfjdkjfkdfj
dlfkjdjffpeureoiuiureiuierABC67890fkdlfkdkfdfkf
this is the situation....
how can i get only 5 number after ABC and all the number are store in array....
thanks
Dim theString as string = "ABC12345"
Dim theTextIWant as string = theString.SubString(theString.IndexOf("ABC"),5)
you put the number o chars you want to coppy in TextIWant
as suggested, read the line then do a substring and index of:
'create an array:
Dim theArrayList as new ArrayList()
'While loop from the above code sample given
Dim currentLine as String = theCurrentLine.ReadLine()
Dim theString as String = currentLine.SubString(currentLine.IndexOf("ABC"), 5)
theArrayList.Add(theString)
'end while
this will:
you may wish to do some error trapping also as the code I posted was just rough and straight to the point :-)