SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Nov 2009
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Createing a variable from the start of a string

    Hi there,

    I am reading data from a db and and building variables depending on the data extracted. I am having a problem trying to work out how I can achieve the following.

    My record could contain data as follows

    My Village in the (Peak District)
    My Town in (Ohio)

    All I want to do is scan between the first character up to the first Right bracket and associate it to a variable. As you can see the length at the beginning of the string is likely to be different for every record. So for the above examples I would get the variables of "My Village in the" and "My Town in"

    Is this possible?

    Thanks

  2. #2
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,629
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Code:
    sData = "My Village in the (Peak District)"
    iOpen = InStr(sData,"(") + 1
    iClose = InStr(sData,")")
    sVillage = Mid(sData,iOpen,iClose-iOpen)
    
    sData = "My Town in (Ohio)"
    iOpen = InStr(sData,"(") + 1
    iClose = InStr(sData,")")
    sTown = Mid(sData,iOpen,iClose-iOpen)
    
    Response.Write sVillage & "<br>" & sTown
    Ian Anderson
    www.siteguru.co.uk


Bookmarks

Posting Permissions

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