Results 1 to 9 of 9

Thread: Parsing problem

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    Calgary Alberta
    Posts
    359

    Post

    I need to reverse a string, or at least read from the end of it. I need to check an entry in a CSV file and that enty is 8 from the end. So basically I need to reverse the string and use InStr() from the end (right side). THe CSV is pretty large so I can't read it from the front, it takes too long. Any suggestions?

    ------------------
    'cos Buzby says so!'

  2. #2
    Frenzied Member Buzby's Avatar
    Join Date
    Jan 1999
    Location
    UK
    Posts
    1,670

    Post

    right(TheString,8) will give you the last 8 chars of the string - or is this barking up the wrong tree.

    Nice tag line!!



    ------------------
    Mark "Buzby" Beeton
    VB Developer
    [email protected]



  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    Calgary Alberta
    Posts
    359

    Post

    That's what I first thought of but either I'm using it wrong or it doesn't work because using

    strTemp = Right(strLine, len(strLine))

    just makes strTemp = strLine. I need to set the lenght to the total length because I'm not sure how large the line is. There are memo fields and large text strings that can be empty or full. Would it make a difference if the len() was shorter than the entire string?

    I told you that I had found a new tab line :-)

    PS: The control is working great, thanks again!

    ------------------
    'cos Buzby says so!'

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    Calgary Alberta
    Posts
    359

    Post

    I did a search in the Tips section and the only suggestion was to do this:

    for lngTemp = len(strLine) to 1 step -1
    strTemp = strtemp & mid(strLine, lngtemp,1)
    next lngTemp


    But this has to loop through the file (even if I changed the 'to 1' with len(strLine)/2 it will still require a fair amount of looping. I really want to avoid this because I have to check for everyline for this section and if it equals "Open", then I have to loop the entire line already once. This looping is already taking a long time.


    ------------------
    'cos Buzby says so!'

  5. #5
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    The Right function uses two parameters, the source string the number of characters on the right end that you want to extract. So when you use len(strLine) in

    strTemp = Right(strLine, len(strLine))

    you are you saying that you want to extract the total length of the line and put it into strTemp.

    Unless I totally misunderstand what you want to do, Buzby's original suggestion which was essentially

    strTemp = Right(strLine, 8)

    will extract the rightmost 8 characters regardless how long the line is.

    ------------------
    Marty
    What did the fish say when it hit the concrete wall?
    > > > > > "Dam!"

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    Calgary Alberta
    Posts
    359

    Post

    I guess I wasn't clear in my original post. I want to grab the right most chars but I need to get them reversed somehow. Basically I need to go 8 fields in from the right in a 32 field line from a CSV file. The 8th field tells me whether to write this line into the Database Table or to skip it. I can't go from the front because the line's can get rather long. Any suggestions to do this would be great.

    ------------------
    'cos Buzby says so!'

  7. #7
    Guest

    Post

    netSurfer,
    Combine the two functions here:

    strTemp2 = Right(strLine,8)
    for lngTemp = 1 to 8
    strTemp = mid(strTemp2, lngtemp,1) & strTemp
    next lngTemp

    Hope this helps


    ------------------
    Boothman
    There is a war out there, and it is about who controls the information, it's all about the information.


  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    Calgary Alberta
    Posts
    359

    Post

    Boothman, that still leaves me with the problem of having to loop through it to the pot I need and since I'm not sure exactly where it is, it makes it more difficult. I sorta gave up and just used the loop (very similar to what you did except counted from 8 to 1) and it works, it's just a little slower than I like. Oh well.

    Thanks for the help everyone.


    ------------------
    'cos Buzby says so!'

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    Calgary Alberta
    Posts
    359

    Post

    For the curious:

    I decided to use the VS View FlexGrid. IT will automatically load CSV files and it's alot easier checking cell values at the end :-) I decided that the cost of it offsets the pain in the a$@ of writing the code and the amount of time it takes to do manually. Thanks again.


    ------------------
    'cos Buzby says so!'

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