Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.
Hi all, please see this major site announcement: https://www.boards.ie/discussion/2058427594/boards-ie-2026

InStr VB.net question

  • 13-11-2006 02:25PM
    #1
    Registered Users, Registered Users 2 Posts: 8,968 ✭✭✭


    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, Registered Users 2 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, Registered Users 2 Posts: 2,929 ✭✭✭Ginger


    Or just use InStrRev for attacking it from the other end


  • Moderators, Science, Health & Environment Moderators Posts: 9,259 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, Registered Users 2 Posts: 2,781 ✭✭✭amen


    what the 20 for?


  • Advertisement
  • Moderators, Science, Health & Environment Moderators Posts: 9,259 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
Advertisement