Solved

Replace last character in string if it is "\"

Posted on 2007-11-27
5
1,345 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 119

Accepted Solution

by:
Rey Obrero earned 500 total points
ID: 20361906

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

Expert Comment

by:Rey Obrero
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 119

Expert Comment

by:Rey Obrero
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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.

757 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now