读书人

字符串处理,该怎么处理

发布时间: 2012-03-08 13:30:13 作者: rapoo

字符串处理
给定类似于文件路径字符串
C:\Documents and Settings\zhou.xiaoqing\North(270).xls
现在提取2个字符串
一个是North,还有个是North(270)
很简单。。。麻烦好心人给个代码。。。
SSIS 2005中只能用VB写脚本。。好郁闷

[解决办法]
instr()断定(的位置,直接取就行!如果不会用instr,那么msdn或google都行!!
[解决办法]
确实很简单的,楼主你不能就浅入研究下吗,还是给你个直接就可以拿来用的吧。


'此代码由“正则测试工具 v1.1.35”自动生成,请直接调用TestReg过程

VB code
Private Sub TestReg()    Dim strData As String    Dim reg As Object    Dim matchs As Object, match As Object    strData = "C:\Documents and Settings\zhou.xiaoqing\North(270).xls"    Set reg = CreateObject("vbscript.regExp")    reg.Global = True    reg.IgnoreCase = False    reg.MultiLine = True    reg.Pattern = "\\(([^\\]*?)\(.*?\))\.xls"    Set matchs = reg.Execute(strData)    For Each match In matchs        'Debug.Print match.Value        Debug.Print match.SubMatches(0) & vbtab & match.SubMatches(1)    NextEnd Sub
[解决办法]
VB code
Private Sub Command1_Click() Dim a As String, b As String a = "C:\Documents and Settings\zhou.xiaoqing\North(270).xls" a = Mid(a, InStrRev(a, "\") + 1, InStrRev(a, ".") - InStrRev(a, "\") - 1) b = Mid(a, 1, InStr(a, "(") - 1) MsgBox a & "," & bEnd Sub 

读书人网 >VB

热点推荐