largo_winch
29-11-2011, 09:49
I've tested this little example with "replace" function. Replace Function 2 works fine. But I have problems to use my first replace function. there's something incorrect with "parsecount" command I have done wrong.
I wanted to replace one word "little" with another one "young" and took a string with tab spaces (+$SPC+).
' Empty GUI script created on 11-28-2011 12:41:14 by (ThinAIR)
Uses "console"
Dim Pieces() As String
'---------------------------> Parse replace not eniterly ok ----------------------------------------------------->
Function ParsRepl (OrigString As String, Delim As String, myFoldNum As Long, ReplString As String) As String
Local strx As String
' Dim Pieces(ParseCount(OrigString, Delim)) As String
strx = Pieces(ParseCount(OrigString, Delim))
Parse$(OrigString, Pieces(), Delim)
Pieces(myFoldNum) = ReplString
Function = Join$(Pieces(),Delim)
End Function
'------------------------> Parse replace ok --------------------------------------------------------------------->
Function ParsRepl2 (OrigString As String, Delim As String, myFoldNum As Long, ReplString As String) As String
Local r,n As Long
For r = 1 To myFoldNum -1
n = InStr(n+1,OrigString,Delim)
Next
Function = LEFT$(OrigString,n)+ReplString+Delim+RIGHT$(OrigString,-InStr(n+1,OrigString,Delim))
End Function
'---------------------------> MAIN ---------->
Function TBMain () As Long
Local mytest As String
mytest = ("Marilyn"+$SPC+"had"+$SPC+"a"+$SPC+"little"+$SPC+"cat")
MsgBox 0, mytest
'mytest = ParsRepl2(mytest,""+$SPC+,4,"young") 'ok :)
mytest = ParsRepl(mytest,""+$SPC+,4,"young")
MsgBox 0, mytest
End Function
bye, largo
I wanted to replace one word "little" with another one "young" and took a string with tab spaces (+$SPC+).
' Empty GUI script created on 11-28-2011 12:41:14 by (ThinAIR)
Uses "console"
Dim Pieces() As String
'---------------------------> Parse replace not eniterly ok ----------------------------------------------------->
Function ParsRepl (OrigString As String, Delim As String, myFoldNum As Long, ReplString As String) As String
Local strx As String
' Dim Pieces(ParseCount(OrigString, Delim)) As String
strx = Pieces(ParseCount(OrigString, Delim))
Parse$(OrigString, Pieces(), Delim)
Pieces(myFoldNum) = ReplString
Function = Join$(Pieces(),Delim)
End Function
'------------------------> Parse replace ok --------------------------------------------------------------------->
Function ParsRepl2 (OrigString As String, Delim As String, myFoldNum As Long, ReplString As String) As String
Local r,n As Long
For r = 1 To myFoldNum -1
n = InStr(n+1,OrigString,Delim)
Next
Function = LEFT$(OrigString,n)+ReplString+Delim+RIGHT$(OrigString,-InStr(n+1,OrigString,Delim))
End Function
'---------------------------> MAIN ---------->
Function TBMain () As Long
Local mytest As String
mytest = ("Marilyn"+$SPC+"had"+$SPC+"a"+$SPC+"little"+$SPC+"cat")
MsgBox 0, mytest
'mytest = ParsRepl2(mytest,""+$SPC+,4,"young") 'ok :)
mytest = ParsRepl(mytest,""+$SPC+,4,"young")
MsgBox 0, mytest
End Function
bye, largo