How to count the number of letters between two same values for a column in a table.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • PravinRamteke
    New Member
    • Apr 2010
    • 2

    #1

    How to count the number of letters between two same values for a column in a table.

    Col1 Col2 Col3 Col4 Col5
    Pravin 6 XYZ test Address
    Pravin 4 PQR test Address
    Pravin 3 hkkh test Address
    Pravin 3.2 PQR test Address
    Pravin 7.2 jhhkhkh test Address
    Pravin 2.5 bbmbmb test Address
    Pravin 2.5 PQR test Address
    Pravin 3.2 PEN test Address

    I have this table.In Col3, 2nd row i have a value PQR(which is the first appearance of this value) and in the second last row in the same column i have again PQR(which is the last appearance of this value). I have to calculate the number of letters between these two values, traversing from col4,col5, col1, col2 and so on till we reach col3 of 2nd last row(last appearance of PQR).

    Any help would be appreciated.
  • GaryTexmo
    Recognized Expert Top Contributor
    • Jul 2009
    • 1501

    #2
    What do you have so far?

    If you haven't done it already, your first step should be to identify the first and last rows that contain your target value.

    Comment

    • PravinRamteke
      New Member
      • Apr 2010
      • 2

      #3
      Originally posted by GaryTexmo
      What do you have so far?

      If you haven't done it already, your first step should be to identify the first and last rows that contain your target value.
      Thx for the reply Gary.
      I haven't done it yet, because i am not sure about the approach.Can you help me in a sample code(or a psuedo) for this.

      Comment

      • GaryTexmo
        Recognized Expert Top Contributor
        • Jul 2009
        • 1501

        #4
        I'll do my best to help you work though it, but I won't give you any sample code, at least not until you start writing your own code for it.

        As I said, what you need to do is programatically identify the first and last rows that contain your target value. Thlintoq often says around here, the best way to attack a problem is to start simple. There's a lot of wisdom in that stance... lets imagine a list of strings and we want to find the index of the first and last occurrence of a particular string in that list.

        Imagine the list...

        "pig", "chicken", "cow", "chicken", "pig", "horse", "duck", "cow", "horse", "cow", "cow", "cow", "sheep", "chicken", "cow", "pig"

        You have this list, now you need to process it. That's your first step. The second step is to identify the first occurrence of something, lets say "cow". Thirdly, you need to determine the last occurrence of "cow".

        (I'm sorry, I can't provide you with the code as not only would it violate the rules of this forum, but you wouldn't take anything away from this. I could give you the answer, but what about when the next problem comes along? You need to learn to think for yourself and solve your own problems. It doesn't mean you can't get help, but it does mean you can't just have answers)

        Comment

        Working...