Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

put split back together?

Status
Not open for further replies.

cyprus106

Programmer
Joined
Apr 30, 2001
Messages
654
I've got to split a string 2 times, one inside of the next to find and change a certain variable. When I change that variable, I want to put it back in the original string but my methods seem to fail repeatedly.
What I do is split the string by ':'s first, then by ','s inside that. then i tried to step back out the way i came in by putting the second split inside the first and the first inside the original string again. Didn't work

Here's my code. Hope someone asphigher than me knows what to do. thanks!

inItems = Split(Request.Cookies("SavedItems"), ":")
For x = 0 to UBound(inItems) - 1
itemProps = Split(inItems(x), ",")


if itemProps(1) = request("item_name") then
itemProps(0) = int(itemProps(0)) + 1

inItems(x) = ""
For j = 0 to UBound(itemProps) - 1
inItems(x) = inItems(x) + itemProps(j)
next


Dim strItems
For i = 0 to UBound(inItems) - 1
strItems = strItems + inItems(i)
strItems = strItems & ":"
next

response.Cookies("SavedItems") = strItems
end if
Next

Cyprus
 
Have you thought of some form of REPLACE

strw = Replace(Request.Cookies("SavedItems"), _
";" & request("item_name") & ";", "")

Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
errr, how about Join()?

Join takes an array and a character and creates a delimited string for you, ie the opposite of Split. Therefore you could:
Code:
a = "a,b,c,d:1,2,3,4"
'split 1
array1 = split(a, ":")

'split an inner array
inner1 = split(array1(0),",")

'change a value
inner1(3) = "e"

'join inner array back to correct index
array1(0) = Join(inner1,",")
a = join(array1,":")

Response.Write a
This will substitute the 4th entry in the first set (d) with e.

-Tarwn


01010100 01101001 01100101 01110010 01101110 01101111 01101011 00101110 01100011 01101111 01101101
29 3K 10 3D 3L 3J 3K 10 32 35 10 3E 39 33 35 10 3K 3F 10 38 31 3M 35 10 36 3I 35 35 10 3K 39 3D 35 10 1Q 19
Get better results for your questions: faq333-2924
Frequently Asked ASP Questions: faq333-3048
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top