Rabu, 01 Januari 2014

Re: [MS_AccessPros] help with a trimming a string

 

Is anyone else having issues with starting a new topic? I click the button until it is not fun anymore.

Jim Wagner


Sent from Yahoo! Mail for Windows 8

From: Thomas Ewaldtewald@yahoo.com>
Sent: ‎Sun, ‎Dec‎ ‎29‎, ‎2013 at ‎7‎:‎06‎ ‎AM
To: MS_Access_Professionals@yahoogroups.com MS_Access_Professionals@yahoogroups.com>
Subject: Re: [MS_AccessPros] help with a trimming a string

I'll use a string variable of strPath, and an integer variable of intSlash. You can do without the latter by combining the last two formulas, but it's easier to understand when you use the integer.

You can start with:

If right(strPath,1) = "\" then strPath = left(strPath,len(strPath)-1)

If you know for sure that the last character is a backslash, then you can just use:

strPath = left(strPath,len(strPath)-1)

So now, from your example, you have: "C:\mainpath\subfolder\subfolder"

Now that you know the last character is not a backslash, you want to find the last backslash that remains:

intSlash = InStrRev(strPath, "\")

InString (InStr) finds the first instance of a substring ("\" in this case) within a string (the variable strPath in this case). We're using InStrRev, which reverses the process in a sense, finding the first instance starting from the end of the string, not the beginning.

The variable intSlash now contains the location of the final backslash (position 22 in your example). Just delete what comesafter it:

strPath = left(strPath, intSlash)

I hope this is all clear. This will work in Accessor Excel, BTW. Feel free to ask any questions.

Tom Ewald
Detroit Area


From: "glcass58@yahoo.com"
To: MS_Access_Professionals@yahoogroups.com
Sent: Saturday, December 28, 2013 4:46 PM
Subject: [MS_AccessPros] help with a trimming a string

Hi all,
This is probably a simple question but I just can't seem to figure it out! In my recordset I have a field that is a folder path. I need to take the folder path and trim off the last folder level. So I want to take this:
"C:\mainpath\subfolder\subfolder\"
and trim it to:
"C:\mainpath\subfolder\"
The number of subfolders and subfolder names will vary with each record.
Thanks in advance for your help!!!


__._,_.___
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (4)
Recent Activity:
.

__,_._,___

Tidak ada komentar:

Posting Komentar