Need Help - "Circular" string comparaison

  • Thread starter Thread starter Rogers
  • Start date Start date
Thx Andy, Good thinking. However in my implementation this algorithm could
lead to false positive:

Source: 1 1 3 3 -> Double 1 1 3 3 1 1 3 3
Compare: 3 3 1 1
IndexOf(3 3 1 1) <> -1

You've tried that twice?! Surely you can _see_ "3311" in your double
string!

Look, here it is ---------------v
Source: 1 1 3 3 -> Double 1 1 3 3 1 1 3 3
Compare: 3 3 1 1
IndexOf(3 3 1 1) <> -1

"3311" is a rotation of "1133" by order 2.
i.e.
3311 (order 0)
3113 (order 1)
1133 (order 2)
1331 (order 3)

Dim s As String = "11331133"
Debug.WriteLine( s.IndexOf( "3311" ) )

If that says anything other than "2" I suggest you have typed it
incorrectly! Either that or I am surrounded by madness... ;)

Rgds,
 
I could Split the string to an array but the string comes with no space and
unlike VB6 inplementation of the Split function, .NET doensn't split string
if the split character is an empty string (ie. Spilt("12345","") =
Array(0)="12345"). I can't find a way to split a string without separators.
Stupid implementation!

string.ToCharArray() would do that ;p
 
Back
Top