Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

InStr VB.net question

Options
  • 13-11-2006 2:25pm
    #1
    Registered Users Posts: 7,677 ✭✭✭


    Hi,

    I have the following string

    AVSADDRESSRESULT =
    AUTHCODE =
    PASREF = 11616951961804
    MERCHANT_ID = es
    ORDER_ID = 3000036
    TIMESTAMP = 20061024140636
    RESULT = 103

    I need to strip over the value after result but when I do a InStr it picks up the result in the avsaddressresult.

    Can I get my code to skip this one and select the next one?

    intPos = InStr(1, UCase(strOrderText), "RESULT=")


Comments

  • Registered Users Posts: 2,781 ✭✭✭amen


    loads of ways to do this
    you could Split the string and seach the array positions
    or
    if you have a match check to makes sure there are not additional characters to either side and if there are restart the search
    or
    if the format is alwasy with same with the result you are looking for at the end then use RevInStr or maybe its InStrRev (can't remember)


  • Closed Accounts Posts: 82 ✭✭cyberbob


    amen wrote:
    loads of ways to do this

    alot of which are overkill...
    Trampas wrote:
    Can I get my code to skip this one and select the next one?
    intPos = InStr(20, UCase(strOrderText), "RESULT=")
    ie start the search after "AVSADDRESSRESULT"

    again as amen said, assuming your output is always that format.


  • Registered Users Posts: 2,931 ✭✭✭Ginger


    Or just use InStrRev for attacking it from the other end


  • Moderators, Science, Health & Environment Moderators Posts: 8,950 Mod ✭✭✭✭mewso


    So has nobody moved on to using the string object methods. i.e.
    intPos = strOrderText.ToUpper.IndexOf("RESULT=", 20)

    I always assumed the new methods were more efficient but who knows.


  • Registered Users Posts: 2,781 ✭✭✭amen


    what the 20 for?


  • Advertisement
  • Moderators, Science, Health & Environment Moderators Posts: 8,950 Mod ✭✭✭✭mewso


    20 is the start position as per cyberbob's suggestion.
    The other option is to find the bit before the RESULT part you want:-

    intPos = strOrderText.ToUpper.IndexOf("TIMESTAMP =")
    intPos = strOrderText.ToUpper.IndexOf("RESULT =", intPos) 'should always find the result string after timestamp avoiding the result string at the beginning.


  • Closed Accounts Posts: 46 theslick


    if those are linefeeds

    intPos = InStr(1, UCase(strOrderText), vbCrLF + "RESULT = ")


Advertisement