在REPLACE函数中使用通配符的MSAccess [英] MSAccess using a wildcard in the REPLACE function

查看:152
本文介绍了在REPLACE函数中使用通配符的MSAccess的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试做一些简单的事情,但我不明白为什么它不起作用.我真的是MS Access VBA的新手.

I'm trying to do something simple and I don't understand why it's not working. I'm really new to MS Access VBA.

我在文本框中有一个字符串:

I have a string in a textbox :

\\ p9990cdc \ C $ \ Temp

\\p9990cdc\C$\Temp

我想将其转换为:
C:\ Temp

I want to turn it into :
C:\Temp

我正在尝试:

strSelectedFile = Replace(strSelectedFile, "\\*\C$", "C:")

它不起作用.

不确定RegEx为什么也不起作用:

Not sure why RegEx doesn't work either :

strSelectedFile = Replace(strSelectedFile, "\\[\w]\C$", "C:")

所有设置都正确,因此问题出在该替换代码上,因为如果我尝试例如:

Everything is set properly so the problem lies exactly in that replace code, because if I try for example :

strSelectedFile = Replace(strSelectedFile, "C$", "C:")

它有效并且成功地用C替换了C $:

It works and sucessfully replaces the C$ with C:

\ p9990cdc \ C:\ Temp

\p9990cdc\C:\Temp

我该如何进行这项工作?

How can I make this work?

非常感谢您的时间!

推荐答案

您可以改用Mid(Instr())查找$的索引,然后从那里获取字符串(减1以保留目录字母). /p>

You could instead use Mid(Instr()) to find the index of $ and grab the string from there (minus 1 to keep the directory letter) onwards.

strSelectedFile = Replace(Mid(strSelectedFile, InStr(strSelectedFile, "$") - 1, Len(strSelectedFile)), "$", ":")

这篇关于在REPLACE函数中使用通配符的MSAccess的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆