Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts

    regExp in string concat. ?

    I think it might be the lunchtime pub visit, but I'm having real problems with the following:

    Code:
    if isfileexists(server.mappath("images")&"\dbImages\"&sku_num&"_exterior_1s.jpg") then
    I want to replace the "exterior" with a simple regExp that will match any word but I'm a little confused how to integrate that with the existing string concatenation.

    Could anyone pint - sorry, freudian slip there - point me in the right direction?

  • #2
    Regular Coder
    Join Date
    Dec 2002
    Location
    France
    Posts
    522
    Thanks
    0
    Thanked 0 Times in 0 Posts

    regex

    dim _myReGex as string ="YourRegex"

    dim _name as String = Regex.Replace ("_exterior_1s.jpg", "exterior", _myReGex)

    dim _file as String = (server.mappath("images")&"\dbImages\"& sku_num &"_"& _name)


    if isfileexists(_file) then

    ......but it is a bit heavy in that way

    you could do a small function PathBuilder

  • #3
    Regular Coder
    Join Date
    Oct 2003
    Location
    London, UK
    Posts
    411
    Thanks
    0
    Thanked 1 Time in 1 Post
    If I have interpreted your post correctly, then what you want to do is find whether there is any file in the dbImages folder whose filename starts with (the value of) sku_num, and ends with "_1s.jpg". Is this correct?

    If so, you can't do it the way you are attempting. Instead, you should use the FSO to get the folder, and iterate through the files contained within, running an appropriate RegEx on each filename.

    Does that help?
    Marcus Tucker / www / blog
    Web Analyst Programmer / Voted SPF "ASP Guru"

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I agree with marco... you should just loop through the files (there is a GREAT example in the sticky posts in this forum on that, by the way, brainjar's script), and then check to see if the filename matches your criteria, either using regular expressions or plain old string matching (i.e. Left(), InStr() or whatever).

    Obviously if all of your files have underscores in appropriate places you could split the string on underscores into an array, and just check the appropriate array number for the right string value as well, although a regular expression might be the best.

    I use this kind of programming logic if I'm in a real hurry sometimes. Kind of like Bruce Li's martial arts philosophy - "Use what works".
    Last edited by whammy; 10-13-2003 at 03:08 AM.
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #5
    Regular Coder
    Join Date
    Oct 2003
    Location
    London, UK
    Posts
    411
    Thanks
    0
    Thanked 1 Time in 1 Post
    Glad you agree, but not only is it "what works", it is the *only* way to do it (without rolling your own file system class or COM)!!
    Marcus Tucker / www / blog
    Web Analyst Programmer / Voted SPF "ASP Guru"

  • #6
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I was referring to the use of InStr() or splitting the string up as opposed to regular expressions.
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)


  •  

    Posting Permissions

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