Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
This sub sections out a substring from within the ...
Author:
SirCodezAlot
E-mail:
Click to e-mail author
Submitted:
8/23/2002
Version:
VB3, VB4, V
Compatibility:
VB3, VB4, VB5, VB6, VB.NET
Category:
String Manipulation
Views:
12230
This sub sections out a substring from within the given string, starting at the given point, and ending at the given character as long as it is not within parentheses or quotation marks. This is very useful when writting command and expression parasers.
Declarations:
'none
Code:
Public Function GetString(ByVal start As Integer, ByVal str As String, ByVal endStr As String) As String Dim inString As Boolean 'Set to True when inside 'quotation marks Dim parNum As Integer 'Number of beginning 'parentheses found inString = False parNum = 0 'Loop around every character from the given start For a = start To Len(str) 'If the end character is found If Mid(str, a, Len(endStr)) = endStr Then 'If the end character isn't inside parentheses or quotes If parNum = 0 And inString = False Then Exit Function End If End If 'If a quote mark is found If Mid(str, a, 1) = Chr(34) Then 'If we're inside quote marks, flag that we're not inside them 'anymore, otherwise flag that we're inside them now If inString = False Then inString = True Else inString = False End If 'If beginning parentheses are found outside of quote marks If Mid(str, a, 1) = "(" And inString = False Then 'Increase number of parentheses parNum = parNum + 1 'If end parentheses are found outside of quote marks ElseIf Mid(str, a, 1) = ")" And inString = False Then 'Decrease number of parentheses If parNum > 0 Then parNum = parNum - 1 End If 'Add the next character to the return string GetString = GetString & Mid(str, a, 1) Next a End Function
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement