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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mixing up 3 strings 1

Status
Not open for further replies.

onressy

Programmer
Mar 7, 2006
421
CA
Hi, i have three stings, string one is 5 characters long and so is string 2, string 3 can be any where from 13 to 16 in length.

i would like to shuffle the strings in a patterns like this:

string1= 43095

string2= 95837

string3 = 450098856887021

i would like to mix the string together to produce this

string1-firstvalue string3-firstvalue string1-secondValue string3-secondValue, etc

until all 5 of string 1 are mixed in, then i would like to mix in string 2 but starting from the right hand side, so the end result would be:

4435009059885688975082317

thanks for helping me do the shuffle!
 
ok i have created something that doesn't quite work, i'm trying to shuffle this string: 43095 into every second position at the start of this string: 450098856887021
as well, shuffle 95837 into the ending of the same string.
this is what i have:
Code:
Function shuffle(str1, str2, str3)

str4 = "" 

FOR i = 1 to 5: str4 = str4 & mid(str1,i,1) & mid(str3,i,1): NEXT 

str4 = str4 & mid(str3,6,len(str3)-5) 

FOR i = 1 to 5: str4 = str4 & mid(str3,len(str3)-5+i,1) & mid(str2,i,1): NEXT 

shuffle = str4

End Function 

Response.Write shuffle("43095","95837","450098856887021")
[code]

i get this value: 443500905988568870218975082317
the ending is correct: 8975082317 which is an even shuffle with the right of 450098856887021 and 95837. and the start is correct, shuffling 43095 into 450098856887021 = 4435009059.  The problem is in the middle, this:
443500905988568870218975082317 should actually be:
4435009059 88568 8975082317 (with out spaces, first second sshuffled, last secion shuffled, with unshuffled remaing of 88568)

any thoughts on this?
thanks
 
Try Changing this line
str4 = str4 & mid(str3,6,len(str3)-5)
to
str4 = str4 & mid(str3,6,len(str3)-10)

You don't want to include the last 5 digits as these are to be shuffled in the next step.
 
silly oversight, thanks
one last thing, if you would not mind. now that things are 'shuffled' i'm starting to unshuffle them, this is what i have so far to unshuffle the first set of 43095 from
4435009059885688975082317

Code:
FOR i = 1 TO 5 
str4 = left(str4,i) & mid(str4,i+2) 
NEXT

thanks!
 
try this for unshuffling:

Code:
Function Unshuffle(strIn)

strA = Left(strIn, 10)
strB = Right(strIn, 10)
strC = Mid(strIn, 11, Len(strIn) - 20)

For i = 1 To 10
  If i Mod 2 = 0 Then
      str3Start = str3Start & Mid(strA, i, 1)
    Else
      str1 = str1 & Mid(strA, i, 1)
  End If
Next

str3 = str3Start & strC

For i = 1 To 10
    If i Mod 2 = 0 Then
      str2 = str2 & Mid(strB, i, 1)
    Else
      str3 = str3 & Mid(strB, i, 1)
  End If
Next

Unshuffle = str1 & "," & str2 & "," & str3

End Function
 
Thanks i'm getting a Invalid procedure call or argument: 'Mid'. I'm sure i can work thru this, thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top