| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Split()
Hey guys,
I am having some trouble with the standard Split function. What happens is that I have read data in from a file to a 2D array. But the first element of row in that array needs to be split. So here's what I have: Code:
Dim hackArray
Dim hackString
For i=1 to numEntries
hackString = finalFileData(0,i)
hackArray = Split(hackString)
Response.Write(UBound(hackArray) & "<br>")
if(UBound(hackArray) = 2) Then
Response.Write("here<br>")
finalFileData(sizeDatabase-1, i-1) = hackArray(0)
finalFileData(0, i) = hackArray(1)
end if
Next
numEntries is the number of entries in the 2D array I am trying to split by spaces. I tried printing out the UBound of hackArray each time and every time it read 0. I thought it should at least read 1? Anyways, any ideas why this is happening and what I can do to fix it? |
|
#2
|
||||
|
||||
|
Hi,
you must specify in you split function what you want to split by Code:
hackArray = Split(hackString) to hackArray = Split(hackString," ") hope this helps
__________________
Look! Its a ShemZilla ![]() ![]()
|
|
#3
|
|||
|
|||
|
Quote:
That's not the problem unfortunately. By default, ASP will split on the space. So adding that in gives me the same problem. What I am trying to split is: Generation 578502689 by the space. When I do this: Code:
hackString = finalFileData(0,i) hackArray = Split(hackString," ") it does not split (that is what is in that array, Generation 578502689. But when I do this, Code:
hackArray = Split("Generation 578502689"," ")
it splits fine. Any other ideas? Last edited by lokisapocalypse : February 21st, 2005 at 01:42 AM. Reason: Mistyped |
|
#4
|
||||
|
||||
|
Hi,
what happens when you response.write Code:
hackString = finalFileData(0,i) response.write hackString just want to make sure that hackString is storing the correct value before we move on ![]() |
|
#5
|
|||
|
|||
|
It writes:
Generation 578502689 Also of interest, when I do this: Code:
hackString = finalFileData(0,i) hackArray = Split(hackString," ") Response.Write(UBound(hackArray) & "<br>") it prints out a bunch of 0's. (this code is contained in a loop.) But I don't think having it in a loop is the problem because it doesn't work the first time anyway. |
|
#6
|
||||
|
||||
|
hi,
i am not sure what is going wrong here, have a feeling it has something to do with you array's Code:
For i=1 to numEntries be For i=0 to numEntries shouldn't you start at 0 for your array? Have pm'ed some of the senior members to have a look ![]() |
|
#7
|
|||
|
|||
|
Thank you for having some of the senior members take a look. Starting the array at 1 is intentional. What happens is that there are 83 fields (0 to 82). What is in column one needs to be split and the first element needs to be in space 82 and the second element needs to be in space 0 of the next record. It starts at 1 because the 0th element in the 0th record is correct and does not need to be split.
|
|
#8
|
||||
|
||||
|
Does indeed sound like an array declaration/measurement problem.
What is the value of numentries and how is it determined? If your original 2d array is of the format (0,n), where n is an arbitry number, then using uBound to measure the number of items will return 0, which will obviosly mess with further calculations if you are expecting to get n as the result.
__________________
-
thought-after | my thoughts on web development Get Firefox, the developers browser Budget hosting - recommended [/left] |
|
#9
|
||||
|
||||
|
sounds like that blank space is not blank space. to discover what is that character, have such code:
Code:
Function StrToAscii(str)
Dim result, x
result=""
For x=1 To Len(str)
result=result&Asc(Mid(str, x, 1))
If x<Len(str) Then
result=result&" "
End If
Next
StrToAscii=result
End Function
Dim hackArray
Dim hackString
For i=1 to numEntries
hackString = finalFileData(0,i)
'''lines below are for debugging only, remove when all is working!
Response.Write("hackString raw: "&hackString&"<br />")
Response.Write("hackString ascii: "&StrToAscii(hackString)&"<br />")
'''---------------------------------
hackArray = Split(hackString)
Response.Write(UBound(hackArray) & "<br>")
if(UBound(hackArray) = 2) Then
Response.Write("here<br>")
finalFileData(sizeDatabase-1, i-1) = hackArray(0)
finalFileData(0, i) = hackArray(1)
end if
Next
you can also copy&paste the string directly into this tool: http://www.amitbb.co.il/General_Stu.../StrToAscii.asp ![]() Last edited by Shadow Wizard : February 22nd, 2005 at 03:11 AM. Reason: fixed the function :/ |
|
#10
|
|||
|
|||
|
Shadow Wizard, I tried the ToAscii function and this is what I get:
Quote:
In other words, the hackString ascii prints nothing. I tried to copy and paste the Generation 578502689 to that link you posted but it gave me normal ASCII tabs and when I copied and pasted that into a regular string, it would split just fine. |
|
#11
|
|||
|
|||
|
Quote:
numentries is = numElements / (sizeDatabase-1) numElements = Ubound(filedata) where filedata is the original textfile parsed by '|'. Now I can't use this to parse the entire thing because the last column of each record is not separated by | and that is why I need to do the split function. So in other words, "Generation 578502689" should be Generation as the last element of the previous record and 578502689 should be the first element on the current record. sizeDatabase = 83 because 83 is the number of columns in this database. I divide by sizeDatabase - 1 instead of sizeDatabase because the last column does not get parsed correctly and so I skip over that entry for now but the split (when it works) will populate that last column. |
|
#12
|
||||
|
||||
|
Quote:
oops... my mistake sorry. got nasty bug in that function, Edited my post and fixed that now. take the new StrToAscii function and try again, you would see the true ascii values. ![]() |