Well I gave a stab at it and I think I have something that works. It’s weird but it works.
Given this example:
ABC|\|23|DEF|
would split into:
ABC,|23,DEF
However if I understood Kem then this might not work for |ABC\\|XXX|
Which should parse as ABC\,XXX
My thought was to find an unused character within the string and replace all “\|” with, “”+chr(unused) …
dim x as string = "ABC|\\|EF|GHI"
[code]Public Function split(extends s as string, sep as string, esc as string) as string()
dim tmp as string
dim lst(-1) as string
tmp = s.findUnused(sep)
s = s.replaceAll( esc+sep, esc+tmp)
lst = s.Split(sep)
dim i as integer
dim ts as string
for i=0 to lst.Ubound
ts = lst(i)
lst(i) = ts.replaceAll(tmp, sep)
next
End Function
[/code]
//This method tries to find an unused character to replace an instance of Separator with.
[code]Public Function findUnused(extends src as string, Separator as String) as string
dim anArray(255) as Boolean // 0 to 255 = 256 = 2^8
dim c as uint8
dim idx as integer
dim s as string
//Make an array [0,1,2,3…255]
for idx=0 to 255
anArray(idx) = false
next
// The Separator itself must count.
anArray(asc(Separator)) = true
// Set flag to true for every character found.
for idx=0 to src.LenB
s = src.Mid(idx,1)
c = asc(s)
anArray© = true
next
//Find 1st false
idx = 0
while anArray(idx) and idx <= 255
idx = idx + 1
wend
if idx <> 256 then
return(chr(idx))
end if
return “” //Inescapable.
End Function
[/code]