Join 2 comma delimited number strings in ASP
#1
Scooby Regular
Thread Starter
OK here's a toughie that I'm working on.
Take 2 text strings of integers, separated by a comma for each number: (Strings are held in a database text field).
Example:
String 1 - 12,10,4,8,19
String 2 - 11,7,6,8,10,14
Join them together in one long string, but omit the duplicated numbers.
Result required - 12,10,4,8,19,11,7,6,14
So far I can grab string 1 and string 2, and I can append one to the other, but it includes duplicates.
Anyone any ideas? Currently using arrays to split the strings into single numbers.
DW
Take 2 text strings of integers, separated by a comma for each number: (Strings are held in a database text field).
Example:
String 1 - 12,10,4,8,19
String 2 - 11,7,6,8,10,14
Join them together in one long string, but omit the duplicated numbers.
Result required - 12,10,4,8,19,11,7,6,14
So far I can grab string 1 and string 2, and I can append one to the other, but it includes duplicates.
Anyone any ideas? Currently using arrays to split the strings into single numbers.
DW
#4
Scooby Regular
Thread Starter
Cheers David, but the code looks a bit of an overkill for my purposes as the string is split only into full integers, i.e no text involved.
In theory, if I splt the string into integers, there should be a way of actually using the numbers (maths calc) and removing duplicates, then transferring the numbers back into a string.
Some more searching required I think.
In theory, if I splt the string into integers, there should be a way of actually using the numbers (maths calc) and removing duplicates, then transferring the numbers back into a string.
Some more searching required I think.
#5
Scooby Regular
Join Date: Nov 2001
Location: Leeds - It was 562.4bhp@28psi on Optimax, How much closer to 600 with race fuel and a bigger turbo?
Posts: 15,239
Likes: 0
Received 1 Like
on
1 Post
suppose create two arrays.. take value from second array then compare it to each one of members of the array its joining a match is found then skip else add it in..
Make sense??
David
Make sense??
David
#7
Scooby Regular
Join Date: Nov 2001
Location: Leeds - It was 562.4bhp@28psi on Optimax, How much closer to 600 with race fuel and a bigger turbo?
Posts: 15,239
Likes: 0
Received 1 Like
on
1 Post
not syntax correct but logic correct??
arrayOne(0) = 1
arrayOne(1) = 2
arrayTwo(0) = 1
arrayTwo(1) = 4
for x = 0 to ArrayTwoItemCount
For y = 1 to ArrayOneItemCount
If Arraytwo(y) <> ArrayOne(x) then
ArrayOne(ArrayOneItemCount + 1) = Arraytwo(y)
' Delete item from Array two
' Redim Array?
Else
' Delete Duplicate
End If
Next Y
Next x
Have a look at it in 'edit post'..
David
arrayOne(0) = 1
arrayOne(1) = 2
arrayTwo(0) = 1
arrayTwo(1) = 4
for x = 0 to ArrayTwoItemCount
For y = 1 to ArrayOneItemCount
If Arraytwo(y) <> ArrayOne(x) then
ArrayOne(ArrayOneItemCount + 1) = Arraytwo(y)
' Delete item from Array two
' Redim Array?
Else
' Delete Duplicate
End If
Next Y
Next x
Have a look at it in 'edit post'..
David
Trending Topics
Thread
Thread Starter
Forum
Replies
Last Post