Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trim right Characters 3

Status
Not open for further replies.

duckweb

Programmer
Mar 4, 2003
12
US
Ok...I should know this but I know someone out there will.

I have a variable string....let's say it is:

myimage.jpg

I want to perform some kind of function that returns the following:

myimage

In other words, I want to always trim the last 4 right-most characters from this string. I can't use the Left function cuz the varible name will differ in length. Any ideas? Many thanks!
 
instr and mid function combination should give you the results you need

seeing as it needs to be dynamic you need to search for the "." and then you have the ending of the numeric value
0 is the start

so you need the value of starting position 0 to instr of "." _________________________________________________________
for the best results to your questions: FAQ333-2924
[sub]01001111 01101110 01110000 01101110 01110100[/sub]
onpnt2.gif
[sup] [/sub]
 
Well you could use InStr to find the location of the period and then use the left function for len(str)-locOfPeriod

:)

-Tarwn [sub]01010100 01101001 01100101 01110010 01101110 01101111 01101011 00101110 01100011 01101111 01101101 [/sub]
[sup]29 3K 10 3D 3L 3J 3K 10 32 35 10 3E 39 33 35 10 3K 3F 10 38 31 3M 35 10 36 3I 35 35 10 3K 39 3D 35 10 1Q 19[/sup]
Get better results for your questions: faq333-2924
Frequently Asked ASP Questions: faq333-3048
 
You can still use the "Left" function even though the name is variable in length.

If you're sure it will always be four characters
Left(string, Len(string - 4)

otherwise, you should search for the "." as the others suggested (probably better in the long run)

Left(string, Len(string) - Instr(1, SearchString, ".", 1) - 1)

You might have to play with the syntax, but I think it is correct.
 
wouldn't that return the .jpg portion of the string? _________________________________________________________
for the best results to your questions: FAQ333-2924
[sub]01001111 01101110 01110000 01101110 01110100[/sub]
onpnt2.gif
[sup] [/sub]
 
I see what you're doing there but the len isn't needed
Left(string,Instr(1, string, ".", 1)-1) _________________________________________________________
for the best results to your questions: FAQ333-2924
[sub]01001111 01101110 01110000 01101110 01110100[/sub]
onpnt2.gif
[sup] [/sub]
 
You're right onpnt. Just checked it and was about to write back. Thanks!
 
why me? I was the one that said to try the mid plus instr. [lol]

you both (Tarwn and you) said the staright left( +instr)

[smile] _________________________________________________________
for the best results to your questions: FAQ333-2924
[sub]01001111 01101110 01110000 01101110 01110100[/sub]
onpnt2.gif
[sup] [/sub]
 
Hey onpnt, it doesn't matter where the idea originated. You caught my error and posted code that works in the end. Take a bow! :)
 
Wow, amazing what you miss in the time it takes to add three pages to your web site :p

Thanks for catching the error onpnt, afraid it's Monday and the 4 hours of sleep last night are catching up with me.

-Tarwn [sub]01010100 01101001 01100101 01110010 01101110 01101111 01101011 00101110 01100011 01101111 01101101 [/sub]
[sup]29 3K 10 3D 3L 3J 3K 10 32 35 10 3E 39 33 35 10 3K 3F 10 38 31 3M 35 10 36 3I 35 35 10 3K 39 3D 35 10 1Q 19[/sup]
Get better results for your questions: faq333-2924
Frequently Asked ASP Questions: faq333-3048
 
Thanks to all....I can use your advice to solve my problem!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top