Solved

Replace last character in string if it is "\"

Posted on 2007-11-27
5
1,352 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

730 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