|
1 members (Russ),
11,481
guests, and
1,562
robots. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
S |
M |
T |
W |
T |
F |
S |
|
|
|
1
|
2
|
3
|
4
|
5
|
|
6
|
7
|
8
|
9
|
10
|
11
|
12
|
|
13
|
14
|
15
|
16
|
17
|
18
|
19
|
|
20
|
21
|
22
|
23
|
24
|
25
|
26
|
|
27
|
28
|
29
|
30
|
31
|
|
|
|
|
This is another custom island. This one could be used for ads. This spot is one of the best places for ads on your site to be placed. This can be enabled/disabled on a per forum basis.
|
|
|
|
Joined: Dec 1999
Posts: 30,868
Master Elite Member
|
Function TrimSArray(SArray)
'Function
' Removes all blank elements from the beginning and end of a string array.
' Blank elements in the middle are not affected.
'Parameters
' SArray (String Array) = The string array to work with.
'Return (String Array)
' Returns the specified string array with all blank elements from the beginning And
' end of the array removed.
' If the specified array is empty, function returns an empty string array.
'Notes
' If an element contains any number of the following values and nothing else,
' it is considered blank:
' Space - chr(32)
' Tab - chr(9)
' Linefeed - chr(13)
' Carriage Return - chr(10)
'---
'Initiate variables
Dim FirstUsedElement 'The index of the first non-blank element in the array
Dim LastUsedElement 'The index of the last non-blank element in the Array
Dim ElmCount 'The number of elements in the specified array
Dim C 'General counter
Dim D 'Counter to track the current element in the return buffer
Dim R() 'Return buffer
'Default return value
TrimSArray = R
'Get the number of elements in the specified array
ElmCount = ElementCount(SArray)
'Trap: The specified string array is empty, exit now
If ElmCount = 0 Then Exit Function
'Locate the index of the first non-blank element in the Array
FirstUsedElement = -1 'Cock the value; If it's -1 after the loop, no non-blank elements exist
For C = 0 To ElmCount - 1
If Not IsWhitespace(SArray(C)) Then 'We found a non-blank line
FirstUsedElement = C 'Flag this as the first non-blank element
Exit For
End If
Next
'Trap: We emerged from the loop with -1 (no non-blank lines exist), exit now
If FirstUsedElement = -1 Then Exit Function
'Locate the index of the last non-blank element in the Array
LastUsedElement = -1 'Cock the value; If it's -1 after the loop, no non-blank elements exist
For C = ElmCount - 1 To 0 Step -1
If Not IsWhitespace(SArray(C)) Then 'We found a non-blank line
LastUsedElement = C 'Flag this as the last non-blank element
Exit For
End If
Next
'Now, transfer all elements between FirstUsedElement and LastUsedElement to the return buffer
D = 0 'Set this to the first element we're loading in the return buffer
For C = FirstUsedElement To LastUsedElement
ReDim Preserve R(D) 'Make room for the new line
R(D) = SArray(C) 'Transfer the line from the source array to the return buffer
D = D + 1 'Increment the return-buffer index
Next
'Return the return buffer
TrimSArray = R
End Function
|
|
|
|
|