100分悬赏:2个函数(1、取出2个字符串之间的字符串,2、删除2个字符串之间的字符串)
取中间函数要求:
s= "aXbcdXfefgaXf ",参数:s1= "X ",s2= "X ",结果既可以得到 "bcd "也可以得到 "fefga "
删除中间函数要求:
s= "a[bcdfef]g[af]x ",参数:s1= "[ ",s2= "] ",结果是 "agx "
-------------------------------------------
希望能得到高效算法的函数!
[解决办法]
1.
dim arr() as string,i as integer
arr=split(s, "X ")
For i = 1 To UBound(arr) - 1
MsgBox arr(i)
next i
按照你的例子,试验通过
[解决办法]
第一个问题就不用函数了
Dim uu() As String
uu = Split( " ", "X ")
Msgbox UU(1)
Msgbox UU(2)
第二个问题简单
Private Function getStrInfo(jj As String) As String
Dim aa() As String, bb() As String, ReturnStr As String
aa = Split(jj, "[ ")
ReturnStr = aa(0)
If UBound(aa) > = 1 Then
For X = 1 To UBound(aa)
bb = Split(aa(X), "] ")
If UBound(bb) = 1 Then
ReturnStr = ReturnStr & bb(1)
End If
Next X
End If
getStrInfo = ReturnStr
End Function
[解决办法]
1 如果你的S1=S2,用split分割字串即可,如果不等就用instr mid等处理字符串
[解决办法]
呵呵,
用split即可,不必那么麻烦
[解决办法]
s= "aXbcdXfefgaXf ",参数:s1= "X ",s2= "X ",结果既可以得到 "bcd "也可以得到 "fefga "
删除中间函数要求:
s= "a[bcdfef]g[af]x ",参数:s1= "[ ",s2= "] ",结果是 "agx "
先replace s1为s2
然后split(s2)
索引是偶数的就是删除中间函数
索引奇数就是取中间函数
[解决办法]
简单的问题看道遍地星星和山峰,难问题一个看不到!呵呵。
[解决办法]
LS可真会说话啊
[解决办法]
问题二...我的解法::::
Private Sub Command2_Click()
Dim s As String, s1 As String, s2 As String
s = "a[bcdfef]g[af]x "
s1 = "[ "
s2 = "] "
MsgBox DeleteString(s, s1, s2)
End Sub
Function DeleteString(sA As String, sA1 As String, sA2 As String) As String
Dim iif1, iif2 As Integer
iif1 = InStr(sA, sA1): iif2 = InStr(sA, sA2)
If iif1 < 1 Or iif2 < 1 Then
'do nothing
Else
sA = Mid(sA, 1, iif1 - 1) + Mid(sA, iif2 + 1)
Call DeleteString(sA, sA1, sA2) '调用
End If
DeleteString = sA
End Function
[解决办法]
对于问题一, 看似那么简单, 我个人认为, 并不是那么简单的. 关键是要得到随机得到那2个字符串...
这是学校无聊的题目吧--- 我是这么认为的...
[解决办法]
方法都有了
顶下吧
[解决办法]
顶也代表一种帮助,
我帮助你。
[解决办法]
怎样写人家都回答你啦,你自己动脑袋吧,不外乎:
SPlit,Instr,Instrrev,Mid,Replace,Left,Right,Space,Trim,join...
没人有义务给你娶媳妇,还包你生儿子。
come on!
------解决方案--------------------
VBAdvisor(Sunlight) 说的有道理,已经有这么多答案了,动下脑筋写自己的......
[解决办法]
哦 那也顶下吧
[解决办法]
来晚了,顶一下吧。
[解决办法]
汗... 这还要顶 啊... 就那么几个函数... 慢慢看看吧...
[解决办法]
照LZ这么问,给你1亿分也不够,让你学100年也学不会