'-----------------------------------------------------------------
'Функция Separate делает примерно тоже, что и Delimit,
'но есть несколько отличий:
'1. При любом No возвращается String
'2. Разделитель всегда состоит из одного символа,
но их
'может быть несколько, например если
Delimiters=",;-/", то
'в качестве разделителей будет принят любой из
символов
'",", ";", "-", "/" (в Delimit
разделителем была бы строка ",;-/")
'------------------------------------------------------------------
Function Separate$(CellNumber As Integer, DataString As String, SepString As String)
Dim I As Integer, J As Integer, F As Integer
Dim L As String, N As Integer
Dim C As Integer, C1 As Integer, C2 As Integer, V As String
Dim NumCell As Integer
L = DataString
N = Len(SepString)
ReDim Sep(1 To N) As String * 1
For I = 1 To N
Sep(I) = Mid$(SepString, I, 1)
Next I
NumCell = 0
For I = 1 To Len(L)
F = 0
For J = 1 To N
If Mid$(L, I, 1) = Sep(J) Then F = 1
Next J
If F = 1 Then NumCell = NumCell + 1
Next I
If Len(L) > 0 Then NumCell = NumCell + 1
If CellNumber = 0 Then
Separate$ = LTrim$(RTrim$(Str$(NumCell)))
Exit Function
End If
If NumCell = 0 Then Exit Function
If CellNumber < 0 Or CellNumber > NumCell Then Exit Function
C = 1
C1 = 0
For I = 1 To Len(L)
F = 0
For J = 1 To N
If Mid$(L, I, 1) = Sep(J) Then F = 1
Next J
If F = 1 Then
C = C + 1
If C = CellNumber Then C1 = I: Exit For
End If
Next I
C2 = 0
For I = C1 + 1 To Len(L)
F = 0
For J = 1 To N
If Mid$(L, I, 1) = Sep(J) Then F = 1
Next J
If F = 1 Then C2 = I: Exit For
Next I
If C2 = 0 Then C2 = Len(L) + 1
V = ""
If (C2 - C1) - 1 > 0 Then V = Mid$(L, C1 + 1, (C2 - C1) - 1)
Separate$ = V
End Function