parsing - Parse Text File after a specific word VB.NET -
i have module application reads text file , finds lines specific words in them .
my input looks this
 dealer number: 90402001  dealer name: san tan ford       contract number: 7466564     override class:         contract code: 3417620  portal claim#: 148905   dealer number: 90402001  dealer name: san tan ford       contract number: 7679454     override class:         contract code: 3762406  portal claim#: 149325   dealer number: 90416003  dealer name: car town kia       contract number: dg209507    override class:         contract code: 3110169  portal claim#: 134550   dealer number: 90430005  dealer name: rich ford       contract number: 7380708     override class:         contract code: 3130744  portal claim#: 148537 my output below
 dealer name: san tan ford     contract number: 7466564  dealer name: san tan ford     contract number: 7679454  dealer name: rich ford        contract number: 7380708 all need grab text after "number:"
here have far
 imports system.io   module module1  sub main()      dim str     dim filename = "c:\users\username\desktop\textfile.txt"      dim lines() = file.readalllines(filename)      = 0 lines.length - 1         if lines(i).contains("san tan ford")             str = string.format("{0}{1}", lines(i), lines(i + 1))             console.writeline(str)         elseif lines(i).contains("rich ford")             str = string.format("{0}{1}", lines(i), lines(i + 1))             console.writeline(str)         end if     next  end sub   end module im thinking there lines.after?
 text = lines(i).after("number:")  console.writeline(text) and give me
 7466564  7679454  7380708 ideas?
there several different ways of doing this.  can use indexof , substring find , extract portion of string want.  use regex class find , read matching value, or, simply, use split method.  if consider string "number: " delimiter between 2 other strings, can use split strings before , after delimiter.  so, instance:
dim input string = "contract number: 7380708" dim parts() string = input.split("number: ") console.writeline(parts(0))  ' outputs "contract " console.writeline(parts(1))  ' outputs "7380708" 
Comments
Post a Comment