Solved

Replace last character in string if it is "\"

Posted on 2007-11-27
5
1,347 Views
Last Modified: 2012-06-21
I have a form where the user can select a network directory.  I have a nice little browse button for them to use, but of course they can type it in as well.  I just need to check the string they type in and remove the last character if it is "\".  I tried:

Dim varFolderName As String
varFolderName = txtSharedFolder.Value, "\", "", Len(txtSharedFolder.Value) - 1)

But the value it returns is missing everything up to Len(txtSharedFolder.Value) - 1.  Which in retrospect makes sense.  Now I'm just drawing a blank on what to do.  If there is a way to search from right to left in the string I could use the count function.  Or maybe there is just a better way to approach it completely.  Any suggestions would be helpful.

Dave
0
Comment
Question by:magicspringsadmin
  • 3
5 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 20361906

you can use
If right("yourstring",1) ="\" then
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 20361919

if right("yourString",1)="\" then
     yourString=left("yourString",Len("yourString")-1)
end if
0
 
LVL 61

Expert Comment

by:mbizup
ID: 20361924
Try this:

snew = iif(right(s,1) = "\", left(s,len(s)-1),s)
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 20361943
Dim varFolderName As String

if right(trim(me.txtSharedFolder,1))="\" then

varFolderName = left(trim(me.txtSharedFolder), Len(trim(me.txtSharedFolder)) - 1)

end if
0
 

Author Comment

by:magicspringsadmin
ID: 20367360
Thank you for helping me with that mental block.

Dave
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question