Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1364
  • Last Modified:

Replace last character in string if it is "\"

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
magicspringsadmin
Asked:
magicspringsadmin
  • 3
1 Solution
 
Rey Obrero (Capricorn1)Commented:

you can use
If right("yourstring",1) ="\" then
0
 
Rey Obrero (Capricorn1)Commented:

if right("yourString",1)="\" then
     yourString=left("yourString",Len("yourString")-1)
end if
0
 
mbizupCommented:
Try this:

snew = iif(right(s,1) = "\", left(s,len(s)-1),s)
0
 
Rey Obrero (Capricorn1)Commented:
Dim varFolderName As String

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

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

end if
0
 
magicspringsadminAuthor Commented:
Thank you for helping me with that mental block.

Dave
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now