PDA

View Full Version : ASP Split / Array problem


crmpicco
06-06-2005, 03:55 PM
How can i split this variable up by the : and the / to get just the value and put it into an array. The output is below.


theStr = xmldoc.documentelement.selectnodes("dataElementsMaster").item(0).selectnodes("dataElementsIndiv").item(k).selectnodes("miscellaneousRemarks").item(0).selectnodes("remarks").item(0).selectnodes("freetext").item(0).text



Output:

theStr = ADTNN:870.00/WKEND:20.00/ADDON:0.00/MKUP:20.00/AGTMKUP:40.00/FARE:950.00/FUEL:0.00/TAX:134.20/TTL:1,084.20

So, for example. I just want
870.00
20.00
etc...
in an array

crmpicco
06-06-2005, 03:56 PM
i cant change the XML structure BTW

miranda
06-06-2005, 07:41 PM
Try this


Dim theStr, array1, array2, a, b, newArray
theStr = "ADTNN:870.00/WKEND:20.00/ADDON:0.00/MKUP:20.00/AGTMKUP:40.00/FARE:950.00/FUEL:0.00/TAX:134.20/TTL:1,084.20"
array1 = Split(theStr,"/")
newArray = ""
For a = 0 to Ubound(array1)
array2 = Split(array1(a),":")
newArray = newArray + (array2(1) & "/")
Next
newArray = Left(newArray,(Len(newArray)-1))
Response.Write newArray

Freon22
06-06-2005, 09:20 PM
Try this


Dim theStr, array1, array2, a, b, newArray
theStr = "ADTNN:870.00/WKEND:20.00/ADDON:0.00/MKUP:20.00/AGTMKUP:40.00/FARE:950.00/FUEL:0.00/TAX:134.20/TTL:1,084.20"
array1 = Split(theStr,"/")
newArray = ""
For a = 0 to Ubound(array1)
array2 = Split(array1(a),":")
newArray = newArray + (array2(1) & "/")
Next
Response.Write newArray

I hope you don't mind miranda, but I have never messed with split, left, and right functions much so I couldn't help but play with it some. This line right here is what I would like to know more about.
newArray = Left(newArray,(Len(newArray)-1))
I see what you did with everything else,??, yes I see Len write the number of characters and you use that with your left function. So if the characters change in lenght so will the number. :thumbsup:
The only other thing I see is newArray isn't an array its a variable with a string in it again. Will he have to split it again to turn it into an array like?

newArray = split(newArray, "/")
For b = 0 to Ubound(newArray)
Response.Write newArray(b) & "<br>"
Next
Thats what I love about these boards I get to play, learn, and sometimes help others all at the same time. :) Had to edit: here befoe I forget whats the -1 at the end for? Is it a default or is it indenting 1 character?

miranda
06-06-2005, 11:34 PM
Dim theStr, array1, array2, a, b, newArray
theStr = "ADTNN:870.00/WKEND:20.00/ADDON:0.00/MKUP:20.00/AGTMKUP:40.00/FARE:950.00/FUEL:0.00/TAX:134.20/TTL:1,084.20"
array1 = Split(theStr,"/")
newArray = ""
For a = 0 to Ubound(array1)
array2 = Split(array1(a),":")
newArray = newArray + (array2(1) & "/")
Next
Response.Write newArray
will produce the following:
870.00/20.00/0.00/20.00/40.00/950.00/0.00/134.20/1,084.20/
Note the extra / at the end.
doing this Left(newArray,(Len(newArray)-1)) removes the last / at the end of the string.
the Left() function prints the string starting at the left and then goes the number of characters.
Left(String, Length)
So Breaking the code down, Left(newArray,(Len(newArray)-1))
We used (Len(newArray)-1)) to get the length of the entire string then subtracted 1 from that because we only wanted to remove 1 character.
then if you response.Write newArray will produce
870.00/20.00/0.00/20.00/40.00/950.00/0.00/134.20/1,084.20
Now the / at the end is gone. Now to work with this array simply do this
newArray = Split(newArray,"/")
So now the values are
newArray(0) = 870.00
newArray(1) = 20.00
newArray(2) = 0.00
newArray(3) = 20.00
newArray(4) = 40.00
newArray(5) = 950.00
newArray(6) = 0.00
newArray(7) = 134.20
newArray(8) = 1,084.20

Freon22
06-07-2005, 01:14 AM
miranda, I want to thank you. This has been a fun thread, I normally setup my strings so I don't have a need to break them down. At less now if I end up with a messed up string I have a good idea how to handle it. So if the guy that started this thread doesn't say thanks. Wanted you to know that I am.
Thanks

crmpicco
06-07-2005, 05:14 PM
thanks to all