比如有一个字符串string1: string1=AED_869_CR_01_MZ_W_35516_101.dwg'如何把".dwg"前的10个字符去掉,即要得到:
string1=AED_869_CR_01_MZ_W.dwg
string1=AED_869_CR_01_MZ_W.dwg
解决方案 »
- 学习Access数据库中不同字段的查询方法
- 制作HTML帮助软件从那下载 谢谢
- 100 分解決問題就給~!!!! 在綫等!!!在EXCEL中,我想點擊某個單元格,在同一個頁面中的另一個單元格中顯示這個單元格中的文字,怎
- 请教使用InstallShield打包多个VB工程的问题!谢谢!
- 如何用VB原代码将一个Excel表快速导入MS SQL中一个数据库中????
- 求助!!!!急急,高手请进!!
- 如何使用网络打印机的自定义尺寸?
- 请问编程中出现 Dim f1 As StdDataFormat 中定义类型未定义 怎么修改
- 怎么插不进去?
- 为何recordset变量只能读出一条记录
- [求助]For Each 数据变量类型问题
- Type mismatch 报错原因请教! 急
Left(string1, Len(string1) - 14) & ".dwg"如果后面不是".dwg"的话,或者.dwg不是在末尾,那就要用函数先取.dwg的位置,再截取。
string1=left(string1,instrrev(string1,".dwg")-11) & ".dwg"
.dwg只存在于字符串末尾,简单说,这个字符串表示的是文件名,类似123.doc,aaa.exe,所以,.dwg只是文件名后缀,但不是唯一的后缀名
nn = InStrRev(LCase(string1), ".dwg")
If nn <= 10 + 1 Then
string1 = ".dwg"
Else
string1 = Left(string1, nn - 10 - 1) + Right(string1, Len(string1) - nn + 1)End If
MsgBox string1
string1 = "AED_869_CR_01_MZ_W_35516_101.dwg"
nn = InStrRev(LCase(string1), ".")
If nn <= 10 + 1 Then
string1 = Right(string1, Len(string1) - nn + 1)
Else
string1 = Left(string1, nn - 10 - 1) + Right(string1, Len(string1) - nn + 1)End If
MsgBox string1
还是找“.“的位置然后截取比较好,避免“.docx”之类的。上面有参考代码了,就不贴了。
Private Sub Form_Load()
Dim tmp As String
Dim str As String
tmp = ".dwg" '文件后缀
str = "AED_869_CR_01_MZ_W_35516_101.dwg"
If Len(str) <= 10 + Len(tmp) Then
MsgBox "文件名不足10位"
Else
str = Left(str, Len(str) - InStrRev(str, tmp, 1) - Len(tmp) - 10) & tmp
End If
Debug.Print str
End Sub
dim a
string1="AED_869_CR_01_MZ_W_35516_101.dwg" a=split(string1,".")
if len(a(0))>10 then a(0)=mid(a(0),1,len(a(0))-10)
string1=join(a,".")
msgbox string1
dim a
string1="AED_869_CR_01_MZ_W_35516_101.dwg" a=split(string1,".")
if len(a(0))>10 then a(0)=mid(a(0),1,len(a(0))-10)
string1=join(a,".")
msgbox string1
Dim str1 As String
Dim str2 As String
str1 = "AED_869_CR_01_MZ_W_35516_101.dwg"
str2 = StrReverse(Left(StrReverse(str1), InStr(StrReverse(str1), ".")) + Mid(StrReverse(str1), InStr(StrReverse(str1), ".") + 11, Len(str1)))
Debug.Print str2
End Sub