Results 1 to 4 of 4

Thread: Parsing files....

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2002
    Location
    IL
    Posts
    156

    Question Parsing files....

    hey guys its me again.

    i want to write simple script which gets TXT file, which contains for example:

    Hello world my name is Steave jones from canda,
    i like dogs but i hate big ones...


    now from these lines i want search all steave+space (Steave ) and to cut the first word after it.
    any ideas?



    thx.

  2. #2
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    You will need to use combination of Instr function and Mid function to search and cut the string.

    Here is a simple example

    VB Code:
    1. Dim txt
    2. txt = "Hello world my name is Steave jones from canda,  like dogs but i hate big ones..."
    3.  
    4. Dim pos
    5. Dim SearchWord
    6. SearchWord = "steave "
    7.  
    8. pos = InStr(1, txt, SearchWord, vbTextCompare)
    9.  
    10. response.write Mid(txt, Len(SearchWord) + pos)

    Hope this helps
    Danial
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

  3. #3
    Hyperactive Member Anglo Saxon's Avatar
    Join Date
    Mar 2002
    Location
    Durham, UK
    Posts
    259
    I would use an array to do this :
    Code:
    Dim TextString
    TextString = "Hello world my name is Steave jones from canda, Steave jones likes dogs small dogs , "
    TextString = TextString & "but Steave jones hates big ones... "
    Dim WordArray
    Dim SearchWord
    SearchWord = "Steave"
    
    WordArray = Split(TextString," ")
    
    for i = 0 to UBound(WordArray)
    	if WordArray(i) = SearchWord and i < Ubound(WordArray) then
    		WordArray(i+1) = ""
    		i = i + 1
    	end if
    next
    
    TextString = join(WordArray," ")
    
    response.write(TextString)
    You can even add replace functionality easily :
    Code:
    Dim TextString
    TextString = "Hello world my name is Steave jones from canda, Steave jones likes dogs small dogs , "
    TextString = TextString & "but Steave jones hates big ones... "
    Dim WordArray
    Dim SearchWord
    Dim ReplaceWord
    SearchWord = "Steave"
    ReplaceWord ="Smith"
    WordArray = Split(TextString," ")
    
    for i = 0 to UBound(WordArray)
    	if WordArray(i) = SearchWord and i < Ubound(WordArray) then
    		WordArray(i+1) = ReplaceWord
    		i = i + 1
    	end if
    next
    
    TextString = join(WordArray," ")
    
    response.write(TextString)
    --
    Anglo Saxon

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Aug 2002
    Location
    IL
    Posts
    156
    thx guys i hoe it work ill try it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width