VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Although I use VB's Split function (splits a string into an array at the delimiter you can specif

by Adam Wilson (2 Submissions)
Category: String Manipulation
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Fri 28th December 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Although I use VB's "Split" function (splits a string into an array at the delimiter you can specify), I sometimes need to overlook delimiters

Rate Although I use VB's Split function (splits a string into an array at the delimiter you can specif



'this function is a modified version of the Split() function.  This version allows for
'items to be grouped within a secondary set of delimiters.  For example:
'
'testStr = "'Adam,Tanya,Larry',Emily,April,Cassandra,Laura,'apple,banana,pear'"
'
'testArray = SplitMod(testStr, ",", "'")
'  returns:
'testArray(0) = "Adam,Tanya,Larry"
'testArray(1) = "Emily"
'testArray(2) = "April"
'testArray(3) = "Cassandra"
'testArray(4) = "Laura"
'testArray(5) = "apple,banana,pear"

'see if expression is null
if isnull(initexpression) then
SplitMod = ""
exit function
end if

Dim expression
expression = trim(initexpression)

'see if expression is blank
if (len(expression) < 0) then
SplitMod = ""
exit function
end if


if instr(expression, groupingDelimiter) then
'problem stuff
Dim retArray()
Dim position, ArraySize

ArraySize = 1

do while len(expression) > 0
redim preserve retArray(ArraySize - 1)

'see if we begin with a groupDelimiter
if (left(expression, 1) = groupingDelimiter) then

'get the first item
position = instr(2, expression, groupingDelimiter)

if (position < 1) then
'no ending groupDelimiter tag, so assume to take the rest of the string
retArray(ArraySize - 1) = trim(mid(expression, 2, len(expression) - 1))
expression = ""
else
retArray(ArraySize - 1) = trim(mid(expression, 2, position - 2))
expression = trim(mid(expression, position + 2))
end if

else
'just a regular item
position = instr(expression, delimiter)

if (position < 1) then
'no ending delimiter, so assume to take the rest of the string
retArray(ArraySize - 1) = trim(expression)
expression = ""
else
retArray(ArraySize - 1) = trim(left(expression, position - 1))
expression = trim(mid(expression, position + 1))
end if

end if

ArraySize = ArraySize + 1

loop 

SplitMod = retArray
else
'just use split
SplitMod = Split(expression,delimiter)
end if

end function 'SplitMod


Download this snippet    Add to My Saved Code

Although I use VB's Split function (splits a string into an array at the delimiter you can specif Comments

No comments have been posted about Although I use VB's Split function (splits a string into an array at the delimiter you can specif. Why not be the first to post a comment about Although I use VB's Split function (splits a string into an array at the delimiter you can specif.

Post your comment

Subject:
Message:
0/1000 characters