by Dominick Beckham (1 Submission)
Category: String Manipulation
Compatability: Visual Basic 3.0
Difficulty: Unknown Difficulty
Originally Published: Sun 30th April 2006
Date Added: Mon 8th February 2021
Rating:
(1 Votes)
This code will break a string into parts based on a specific delimiter. Includes four functions. The first, which is not my code, is FindRepl
'' drop this example code into any entry sub (like form_load)
' SomeString = "The quick fox jumped over the lazy brown dog."
' Delimiter = " "
' NewString = FindRepl(SomeString, "fox", "car")
' NewString = FindRepl(SomeString, "dog", "cat")
'' NewString now contains "The quick car jumped over the lazy brown cat."
' WordCount = GetLimit(SomeString, Delimiter)
'' WordCount now contains 9.
' LastWord = ParseWrd(SomeString, Delimiter, WordCount)
' FirstWord = ParseWrd(SomeString, Delimiter, 1)
'' LastWord contains "dog." and FirstWord contains "The".
' RetrBits SomeString, Delimiter, 3, Word3Begins, Word3Ends
' Word3Begins now contains 11 and Word3Ends now contains 13.
'' For more specific examples or for any problems you might be having with these
''old functions, please e-mail me, DominickBeckham at Gmail.
Function FindRepl(Search As String, Find As String, Replace As String) As String
ZZ% = 1
Do
ZZ% = InStr(ZZ%, Search, Find)
If ZZ% = 0 Then Exit Do
Search = Left$(Search, ZZ% - 1) + Replace$ + Right$(Search, Len(Search) - ZZ% - Len(Find) + 1)
Loop Until InStr(Search, Find) = 0
FindRepl = Search
End Function
Function GetLimit(WordSt As String, Parser As String) As Integer
L% = 1: S% = 1
W$ = Parser + WordSt + Parser
Do
S% = InStr(S% + 1, W$, Parser): If S% = 0 Then Exit Do
Select Case S%
Case 0: Exit Function
Case Is > 1: Wd% = Wd% + 1
End Select
L% = S%
Loop
GetLimit = Wd%
End Function
Function ParseWrd(WordSt As String, Parser As String, WordInt As Integer) As String
L% = 1: S% = 1
W$ = Parser + WordSt + Parser
Do
S% = InStr(S% + 1, W$, Parser): If S% = 0 Then Exit Do
Select Case S%
Case 0: Exit Function
Case Is > 1: Wd% = Wd% + 1
If Wd% = WordInt Then ParseWrd$ = Mid$(W$, L% + Len(Parser), S% - L% - Len(Parser)): Exit Do
End Select
L% = S%
Loop
End Function
Sub RetrBits(WordSt As String, Parser As String, WordInt As Integer, ByRef Point1 As Integer, ByRef Point2 As Integer)
L% = 1: S% = 1
W$ = Parser + WordSt + Parser
Do
S% = InStr(S% + 1, W$, Parser): If S% = 0 Then Exit Do
Select Case S%
Case 0: Exit Sub
Case Is > 1: Wd% = Wd% + 1
If Wd% = WordInt Then
Point1 = L%: Point2 = S%: Exit Sub
End If
End Select
L% = S%
Loop
End Sub
No comments have been posted about This code will break a string into parts based on a specific delimiter. Includes four functions. Th. Why not be the first to post a comment about This code will break a string into parts based on a specific delimiter. Includes four functions. Th.