View Full Version : regExp in string concat. ?

10-10-2003, 04:14 PM
I think it might be the lunchtime pub visit, but I'm having real problems with the following:

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?

10-10-2003, 04:38 PM
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

10-11-2003, 12:08 PM
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?

10-13-2003, 02:06 AM
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". :eek:

10-13-2003, 09:14 AM
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)!! :p

10-13-2003, 04:43 PM
I was referring to the use of InStr() or splitting the string up as opposed to regular expressions. :p