Expression to Remove ".tif" extention

JohnLee

Registered User.
Local time
Today, 14:37
Joined
Mar 8, 2007
Messages
692
Good day folks,

I'm having a problem working out how to create an expression that removes the ".tif" extension of a file path.

The data looks like this in it raw form:

J:\20130308\00056273_ELECTRICALRETAILER_001\00056273_ELECTRICALRETAILER_001_3.tif

In my query grid in the filed row I have the following:

ImageRef: Mid([strImagePath],111,38)

which produces the following:

00056273_ELECTRICALRETAILER_001_3.tif
00056273_ELECTRICALRETAILER_001_31.tif

and so on...

What I need to do is remove the ".tif" part of the data. because of the way the path is output with regards to the tif image number, I'm having difficulty in targeting only that data that comes before the ".tif" extension.

Is there a method I can use that will remove the right 4 characters and in conjunction with my expression above produce the following:

00056273_ELECTRICALRETAILER_001_3
00056273_ELECTRICALRETAILER_001_31

Any help pointers suggestions would be most appreciated.

Regards

John

EDIT 14/03/13 15:01 Hours.

I've managed to work out how to get the data without the file extension ".tif" with the following expression:

ImageRef1: Left([strImagePath],Len([strImagePath])-4)

which gives me the following:

\\domgennt.dggroup.com\global\Resource\Applications\UNI\eFlow\IMAGES\20130308\00056273_ELECTRICALRETAILER_001\00056273_ELECTRICALRETAILER_001_3

and

\\domgennt.dggroup.com\global\Resource\Applications\UNI\eFlow\IMAGES\20130308\00056273_ELECTRICALRETAILER_001\00056273_ELECTRICALRETAILER_001_31

How can I combine the following expression with the above expression to get what I need:

Combine - Mid([strImagePath],111,38) with Left([strImagePath],Len([strImagePath])-4)

to get this result:

00056273_ELECTRICALRETAILER_001_3
00056273_ELECTRICALRETAILER_001_31

Any assistance, suggestions or pointers would be appreciated.

Regards

John
 
Last edited:
Hello John, I have written a small function that will do what you want to achieve..
Code:
Public Function removerTIF(tmpStr As String) As String
[COLOR=Green]'-------------------------------------------------------------------------
'   A Function that will take in a String
'   removes the .tif extension.
'
'   Input   : A Normal String, that needs to be stripped
'   Output  : A string free of extension
'   Example :
'   ? removerTIF("\\domgennt.dggroup.com\global\Resource\Application s\UNI\eFlow\IMAGES\20130308\00056273_ELECTRICALRET AILER_001\00056273_ELECTRICALRETAILER_001_3.tif")
'     [/COLOR][COLOR=Green]00056273_ELECTRICALRETAILER_001_3[/COLOR][COLOR=Green]
'--------------------------------------------------------------------------[/COLOR]
    tmpStr = StrReverse(Left(tmpStr, Len(tmpStr) - 4))
    removerTIF = StrReverse(Mid(tmpStr, 1, InStr(tmpStr, "\") - 1))
End Function
You do not have to worry about stripping the .tif first and then extracting just the bit.. the above function will do the both in one go..

Hope this helps..
 
Last edited:
Hi pr2-eugin,

Thanks for you help there, it successfully removes the ".tif" which is what I wanted to remove the leading characters \\domgennt.dggroup.com\global\Resource\Applications\UNI\eFlow\IMAGES\ leaving me with the following:

00056273_ELECTRICALRETAILER_001_3
00056273_ELECTRICALRETAILER_001_31

So the next part is to try and combine :

Mid([strImagePath],111,38) with what you have in your code, is that possible or will I have to deal with it in two parts as I now have.

Your assistance is most appreciated.

Regards

John
 
Hi John, I have modified the code.. Check that again.. I hope that is what you want..
 
Another way:

ImageRef: Mid(Left([strImagePath], Len([strImagePath]) - 4), InStrRev(Left([strImagePath], Len([strImagePath]) - 4), "\") + 1)
 
Hi pr2-Eugin,

That looks like what I need, how do I call that function from within my query grid?

regards

John
 
Just a thought

rather than "hard-coding" the -4 (ie the length of the .tif expression) - you might want to consider searching for the last . character.

if you have a file that is a .jpg, or sometimes a .jpeg then in one case you are looking for 4 chars, in the other 5

by searching for the position of the last . character your routine becomes copletely flexible.
 
Hi Boblarson,

Thanks very much for your post, that was just the ticket I needed. Most appreciated.

Hi Gemma,

As my file extension in this case will always be ".tif" the solution Bob and pre-eugin, was what I was looking for, but I will bear your observation in mind if I need to deploy a similar method that involves other file extenstion types. Thank you for your recommendation.

Hi pr2-eugin,

Thank you for you help I will keep your function handy for when I may need to use it in vb code. Bobs' solution is preferable in this case.

What a great forum, you can always relie on excellent help for experts such as yourselves.

Regards

John
 
Hello John,

You can use Bob's code as well that is just the same as mine but in one single line.. However, I would also consider Dave's suggestion of hardcoding the -4.. So I re wrote the code..
Code:
Public Function removerTIF(tmpStr As String) ' As String
[COLOR=Green]'-------------------------------------------------------------------------
'   A Function that will take in a String
'   removes the .tif extension.
'
'   Input   : A Normal String, that needs to be stripped
'   Output  : A string free of extension
'   Example :
'   ? removerTIF("N01PHRNS1BDH01V.tif")
'     N01PHRNS1BDH01V
'--------------------------------------------------------------------------.[/COLOR]
    Dim patLoc As Integer
    tmpStr = StrReverse(Left(tmpStr, Len(tmpStr) - InStr(StrReverse(tmpStr), ".")))
    patLoc = InStr(tmpStr, "\")
    removerTIF = StrReverse(Mid(tmpStr, 1, IIf(patLoc = 0, Len(tmpStr) + 1, patLoc) - 1))
End Function
I have also added a fail safe to avoid some error that might be thrown your way if in case there is no \ in the String you are passing, based on my test conditions they work, I hope I have got it right.. To use this, copy the above function into a new/pre existing Module (make sure the Module name is not the same as the function name).. Then in your Query, just use..
Code:
ImageRef: removerTIF([strImagePath])
 

Users who are viewing this thread

Back
Top Bottom