|
-
Aug 14th, 2003, 02:23 AM
#1
Thread Starter
Registered User
Why the value inside array becomes empty? [Resolved]
This is the code i work out:
Code:
Private Function funSplitText(ByVal strRinggit As String) As String()
Dim strSplitted() As String = System.Text.RegularExpressions.Regex.Split(strRinggit, " ")
Dim strConcatenatted() As String
Dim strConcatenattedSize As Integer = 0
ReDim strConcatenatted(strConcatenattedSize)
Dim strTemp1 As String
Dim strTemp2 As String
Dim intCounter As Integer
For intCounter = 0 To strSplitted.GetUpperBound(0)
strTemp1 = strTemp1 & String.Concat(" ", strSplitted(intCounter), " ")
strTemp1 = strTemp1.TrimStart(" ")
strTemp1 = strTemp1.TrimEnd(" ")
strTemp2 = strSplitted(intCounter)
If strTemp1.Length > 39 Then
strConcatenattedSize += 1
ReDim strConcatenatted(strConcatenattedSize)
strConcatenatted(strConcatenattedSize) = strTemp2
strTemp1 = strTemp2
Else
strConcatenatted(strConcatenattedSize) = strTemp1
End If
'MessageBox.Show(strConcatenattedSize & ": " & strConcatenatted(strConcatenattedSize))
Next
Dim x As Integer
For x = 0 To strConcatenatted.GetUpperBound(0)
MessageBox.Show(x & ": " & strConcatenatted(x))
Next
Return strConcatenatted
End Function
When i use the last MessageBox to display all value inside the array (strConcatenatted), i found that the array are all empty except the last array, which has value on it.
For example, strConcatenatted's length is 3
the value on:
strConcatenatted(0) is ""
strConcatenatted(1) is ""
strConcatenatted(2) is "abcde"
actually all of them should has string value.
why is this so weird? pls guide me, thank you.
Last edited by albertlse; Aug 21st, 2003 at 07:44 PM.
-
Aug 14th, 2003, 05:30 AM
#2
Member
Not sure but doesn´t the Redim empty the whole array?
Try and set it to 3 and run it 3 times?
-
Aug 14th, 2003, 02:01 PM
#3
Originally posted by Iceman5
Not sure but doesn´t the Redim empty the whole array?
Try and set it to 3 and run it 3 times?
Yes, if ReDim isn't accompanied by the Preserve keyword, the array will empty
-
Aug 14th, 2003, 10:00 PM
#4
Thread Starter
Registered User
kasracer, thanx 4 ur help.
my array is working fine now. it's jes bcoz of the keyword "Preserve"
-
Aug 14th, 2003, 10:36 PM
#5
Originally posted by albertlse
kasracer, thanx 4 ur help.
my array is working fine now. it's jes bcoz of the keyword "Preserve"
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|