473,321 Members | 1,877 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

Need Help - "Circular" string comparaison

I want to compare strings of numbers that have a circular boundary
condition. This means that the string is arranged in a loop without an
end-of-string. The comparaison of two strings now becomes a different
operation than with regular strings because the circular string can be
"rotated", like this:

1 2 3 4 5
2 3 4 5 1
3 4 5 1 2
4 5 1 2 3
5 1 2 3 4

So under the "circular string comparator", all the above strings would be
equal.

I need to do a lot of those comparaisons so optimization is required. What
is the fastest implementation possible in VB.NET? The strings have lenths
ranging from 2 to ~100.

Any ideas?

Thanks in advance for your inputs,

Alain
Nov 20 '05 #1
23 2051
Off the top of my head ( and you have probably already thought about this ).

Pseudo Code
--------------
'Slow Linear Method
For Each String in Array Of Strings
For 1 to String.Length
Check for search String
If Not Found Then Rotate String Else Break Loop

A faster method would may be to take the front or end portion of the string
and search for it and then rotate left or right one character at a time and
repeat the search adding one more letter of the search string each time
until the match is complete. Dont have time to work the code out for you but
this would work as well.

Cheers - OHM





Rogers wrote:
I want to compare strings of numbers that have a circular boundary
condition. This means that the string is arranged in a loop without
an end-of-string. The comparaison of two strings now becomes a
different operation than with regular strings because the circular
string can be "rotated", like this:

1 2 3 4 5
2 3 4 5 1
3 4 5 1 2
4 5 1 2 3
5 1 2 3 4

So under the "circular string comparator", all the above strings
would be equal.

I need to do a lot of those comparaisons so optimization is required.
What is the fastest implementation possible in VB.NET? The strings
have lenths ranging from 2 to ~100.

Any ideas?

Thanks in advance for your inputs,

Alain

Nov 20 '05 #2
Is this what you call 'String' theory ?, your not writing a DNA sequencer
are you ?

Regards OHM
Rogers wrote:
I want to compare strings of numbers that have a circular boundary
condition. This means that the string is arranged in a loop without
an end-of-string. The comparaison of two strings now becomes a
different operation than with regular strings because the circular
string can be "rotated", like this:

1 2 3 4 5
2 3 4 5 1
3 4 5 1 2
4 5 1 2 3
5 1 2 3 4

So under the "circular string comparator", all the above strings
would be equal.

I need to do a lot of those comparaisons so optimization is required.
What is the fastest implementation possible in VB.NET? The strings
have lenths ranging from 2 to ~100.

Any ideas?

Thanks in advance for your inputs,

Alain

Nov 20 '05 #3
In method two, you would only have to rotate the string up to the maximum
length of the search string but flip the search string once one direction
has been exhausted.

This is a very intriguing problem.

OHM
One Handed Man wrote:
Off the top of my head ( and you have probably already thought about
this ).

Pseudo Code
--------------
'Slow Linear Method
For Each String in Array Of Strings
For 1 to String.Length
Check for search String
If Not Found Then Rotate String Else Break Loop

A faster method would may be to take the front or end portion of the
string and search for it and then rotate left or right one character
at a time and repeat the search adding one more letter of the search
string each time until the match is complete. Dont have time to work
the code out for you but this would work as well.

Cheers - OHM





Rogers wrote:
I want to compare strings of numbers that have a circular boundary
condition. This means that the string is arranged in a loop without
an end-of-string. The comparaison of two strings now becomes a
different operation than with regular strings because the circular
string can be "rotated", like this:

1 2 3 4 5
2 3 4 5 1
3 4 5 1 2
4 5 1 2 3
5 1 2 3 4

So under the "circular string comparator", all the above strings
would be equal.

I need to do a lot of those comparaisons so optimization is required.
What is the fastest implementation possible in VB.NET? The strings
have lenths ranging from 2 to ~100.

Any ideas?

Thanks in advance for your inputs,

Alain

Nov 20 '05 #4
w if you split the string into an array of strings (based on the space char)
order that and compare the ordered arrays?

eric

"One Handed Man" <Bo****@Duck.net> wrote in message
news:bp**********@titan.btinternet.com...
In method two, you would only have to rotate the string up to the maximum
length of the search string but flip the search string once one direction
has been exhausted.

This is a very intriguing problem.

OHM
One Handed Man wrote:
Off the top of my head ( and you have probably already thought about
this ).

Pseudo Code
--------------
'Slow Linear Method
For Each String in Array Of Strings
For 1 to String.Length
Check for search String
If Not Found Then Rotate String Else Break Loop

A faster method would may be to take the front or end portion of the
string and search for it and then rotate left or right one character
at a time and repeat the search adding one more letter of the search
string each time until the match is complete. Dont have time to work
the code out for you but this would work as well.

Cheers - OHM





Rogers wrote:
I want to compare strings of numbers that have a circular boundary
condition. This means that the string is arranged in a loop without
an end-of-string. The comparaison of two strings now becomes a
different operation than with regular strings because the circular
string can be "rotated", like this:

1 2 3 4 5
2 3 4 5 1
3 4 5 1 2
4 5 1 2 3
5 1 2 3 4

So under the "circular string comparator", all the above strings
would be equal.

I need to do a lot of those comparaisons so optimization is required.
What is the fastest implementation possible in VB.NET? The strings
have lenths ranging from 2 to ~100.

Any ideas?

Thanks in advance for your inputs,

Alain


Nov 20 '05 #5
On Fri, 21 Nov 2003 05:10:05 GMT, "Rogers" <al**********@msn.com>
wrote:
I want to compare strings of numbers that have a circular boundary
condition. This means that the string is arranged in a loop without an
end-of-string. The comparaison of two strings now becomes a different
operation than with regular strings because the circular string can be
"rotated", like this:

1 2 3 4 5
2 3 4 5 1
3 4 5 1 2
4 5 1 2 3
5 1 2 3 4

So under the "circular string comparator", all the above strings would be
equal.

I need to do a lot of those comparaisons so optimization is required. What
is the fastest implementation possible in VB.NET? The strings have lenths
ranging from 2 to ~100.

Any ideas?


Consider doubling the string.

i.e. 1 2 3 4 5 1 2 3 4 5
You will note that all rotations exist in this string. And if you
incorporate a length check, you get the desired result. Leading to:

Function StringMatch(find As String,source As String) As Boolean
If Len(find) = Len(source) And _
(source & source).IndexOf(find) <> -1 Then
Return True
Else
Return False
End If
End Function

Rgds,

Nov 20 '05 #6
Yesh, I thought of that but it is possible that a match will occur because
of doubling hence giving you an incorrect match. If the strings were like
the example, then I grant you it would work, but it is not robust because of
it.
OHM

_Andy_ wrote:
On Fri, 21 Nov 2003 05:10:05 GMT, "Rogers" <al**********@msn.com>
wrote:
I want to compare strings of numbers that have a circular boundary
condition. This means that the string is arranged in a loop without
an end-of-string. The comparaison of two strings now becomes a
different operation than with regular strings because the circular
string can be "rotated", like this:

1 2 3 4 5
2 3 4 5 1
3 4 5 1 2
4 5 1 2 3
5 1 2 3 4

So under the "circular string comparator", all the above strings
would be equal.

I need to do a lot of those comparaisons so optimization is
required. What is the fastest implementation possible in VB.NET?
The strings have lenths ranging from 2 to ~100.

Any ideas?


Consider doubling the string.

i.e. 1 2 3 4 5 1 2 3 4 5
You will note that all rotations exist in this string. And if you
incorporate a length check, you get the desired result. Leading to:

Function StringMatch(find As String,source As String) As Boolean
If Len(find) = Len(source) And _
(source & source).IndexOf(find) <> -1 Then
Return True
Else
Return False
End If
End Function

Rgds,

Nov 20 '05 #7
I think the original poster needs to comment before Im going to put more
effort into this.

OHM

EricJ wrote:
w if you split the string into an array of strings (based on the
space char) order that and compare the ordered arrays?

eric

"One Handed Man" <Bo****@Duck.net> wrote in message
news:bp**********@titan.btinternet.com...
In method two, you would only have to rotate the string up to the
maximum length of the search string but flip the search string once
one direction has been exhausted.

This is a very intriguing problem.

OHM
One Handed Man wrote:
Off the top of my head ( and you have probably already thought about
this ).

Pseudo Code
--------------
'Slow Linear Method
For Each String in Array Of Strings
For 1 to String.Length
Check for search String
If Not Found Then Rotate String Else Break Loop

A faster method would may be to take the front or end portion of the
string and search for it and then rotate left or right one character
at a time and repeat the search adding one more letter of the search
string each time until the match is complete. Dont have time to work
the code out for you but this would work as well.

Cheers - OHM





Rogers wrote:
I want to compare strings of numbers that have a circular boundary
condition. This means that the string is arranged in a loop
without an end-of-string. The comparaison of two strings now
becomes a different operation than with regular strings because
the circular string can be "rotated", like this:

1 2 3 4 5
2 3 4 5 1
3 4 5 1 2
4 5 1 2 3
5 1 2 3 4

So under the "circular string comparator", all the above strings
would be equal.

I need to do a lot of those comparaisons so optimization is
required. What is the fastest implementation possible in VB.NET?
The strings have lenths ranging from 2 to ~100.

Any ideas?

Thanks in advance for your inputs,

Alain

Nov 20 '05 #8
On Fri, 21 Nov 2003 13:24:08 +0000 (UTC), "One Handed Man"
<Bo****@Duck.net> wrote:
Yesh, I thought of that but it is possible that a match will occur because
of doubling hence giving you an incorrect match. If the strings were like
the example, then I grant you it would work, but it is not robust because of
it.


Can you give me an example of a string that will fail?

Nov 20 '05 #9
my 2 cents ;)
if the order is always like this i think your sollution will be the fastest,
but the question is will it be?
"13254" and "12345" for example, if these are supposed to be equal 2 there
is a problem (and even if this is the case i think it would be best to use
your function first yust for the speed if it matches)

eric

"_Andy_" <wi******@nospamthanks.gov> wrote in message
news:5b********************************@4ax.com...
On Fri, 21 Nov 2003 13:24:08 +0000 (UTC), "One Handed Man"
<Bo****@Duck.net> wrote:
Yesh, I thought of that but it is possible that a match will occur becauseof doubling hence giving you an incorrect match. If the strings were like
the example, then I grant you it would work, but it is not robust because ofit.


Can you give me an example of a string that will fail?

Nov 20 '05 #10
On Fri, 21 Nov 2003 13:56:33 +0000, _Andy_ <wi******@nospamthanks.gov>
wrote:
On Fri, 21 Nov 2003 13:24:08 +0000 (UTC), "One Handed Man"
<Bo****@Duck.net> wrote:
Yesh, I thought of that but it is possible that a match will occur because
of doubling hence giving you an incorrect match. If the strings were like
the example, then I grant you it would work, but it is not robust because of
it.


Can you give me an example of a string that will fail?


By that I mean an example of a string that will cause the algorithm to
fail. If you do find one, I'd be very surprised!

I think you're confusing this with packing and encrpytion algorithms
(the old "ABBAB problems") etc. But they aren't relevant to a match,
as we consider only strings where the lengths are equal. i.e. The
result of the original string appended to itself is a string with the
following properties:

1) All rotations are included, and
2) The zero-rotated string is included twice (at the beginning, and at
the end), and
3) No other characters.

For a search string of size N, there is an infinite number of
rotations. However, there is exactly N-1 distinct rotations.

Remember that,

i Mod N == (i+N) Mod N, where i is the index of rotation.

Given a double string, S, we can see that

S(i Mod N) == S( (i+N) Mod N)

Hence there exists a rotation of the original string in S at every
position. The caveat of the lengths being equal (of the find text and
the source text) means that we never need consider strings that arrive
after N/2.

And that's why it works!

Rgds,
Nov 20 '05 #11
On Fri, 21 Nov 2003 15:22:55 +0100, "EricJ"
<ericRéMo**@ThiSomnipack.be> wrote:
my 2 cents ;)
if the order is always like this i think your sollution will be the fastest,
but the question is will it be?
"13254" and "12345" for example, if these are supposed to be equal 2 there
is a problem (and even if this is the case i think it would be best to use
your function first yust for the speed if it matches)


Although they contain the same digits, 13254 is not a _rotation_ of
12345. I've been trying to think of a more Englishy way of describing
the properties of the rotated string...

Write down the original string.
Mark the last character.
Place a piece of paper to the left of the first character.
REPEAT
Write the character next to the edge of the paper at the end of the
string.
Move the paper to the right by one character.
(You now have the next rotation showing)
UNTIL the paper arrives at the last-character mark.

You have now seen ALL rotations of the string. And when you remove the
paper, you will see the original string appended to itself.
As you said, the algotithm provided is probably the fastest way to
perform the action in VB.NET. The "IndexOf" function could actually be
refined drastically. e.g. Introduce a KMP search. However, the hit
you'd take for implementing that in VB for short strings would
actually be far costlier than using the lowest-level function
available.

Rgds,

Nov 20 '05 #12
In the original post the lengths of all the string are the same, however,
the poster did not make this distinction, he only says that the bounderies
of the search and non existant ( A Circle ). This means for different length
strings an error could occur when using string doubling.. Here is an example
of a false match

String One
ABCEFG ( Double this becomes ABCDEFGABCDEFG )
String 2
GAB

GAB is found in the doubled string.

If however, the string length are allways equal and the rotation is the only
thing which changes, then the string doubling works just fine.

OHM



_Andy_ wrote:
On Fri, 21 Nov 2003 13:24:08 +0000 (UTC), "One Handed Man"
<Bo****@Duck.net> wrote:
Yesh, I thought of that but it is possible that a match will occur
because of doubling hence giving you an incorrect match. If the
strings were like the example, then I grant you it would work, but
it is not robust because of it.


Can you give me an example of a string that will fail?

Nov 20 '05 #13
On Fri, 21 Nov 2003 15:05:45 +0000 (UTC), "One Handed Man"
<Bo****@Duck.net> wrote:
In the original post the lengths of all the string are the same, however,
the poster did not make this distinction, he only says that the bounderies
of the search and non existant ( A Circle ). This means for different length
strings an error could occur when using string doubling.. Here is an example
of a false match

String One
ABCEFG ( Double this becomes ABCDEFGABCDEFG )
String 2
GAB
Are you suggesting that "GAB" could in any way be considered a
rotation of "ABCEFG"???! The fact that "GAB" is a substring of the
cyclic buffer is completely irrelevant.

GAB is found in the doubled string.


In order for the input string to even be considered as a rotation of
the original string THEY BOTH MUST BE OF THE SAME LENGTH. The
algorithm takes care of that by making sure that they are. QED.

Nov 20 '05 #14
_Andy_
Are you suggesting that "GAB" could in any way be considered a
rotation of "ABCEFG"???! The fact that "GAB" is a substring of the
cyclic buffer is completely irrelevant.
No I am not suggesting this is the case, but that the poster did not specify
this to be the case. In fact the post is open to interpretation, it was
ambiguous at best.
In order for the input string to even be considered as a rotation of
the original string THEY BOTH MUST BE OF THE SAME LENGTH. The
algorithm takes care of that by making sure that they are. QED.

Yes Yes, I see what you are saying and in fact I also said you were correct
if this assumption stands, by the way, you dont need to capitalise youre
sentences in order for me to read them, I can read them just as well in
lower or proper case.

OHM
Nov 20 '05 #15
On Fri, 21 Nov 2003 15:36:37 +0000 (UTC), "One Handed Man"
<Bo****@Duck.net> wrote:
_Andy_
Are you suggesting that "GAB" could in any way be considered a
rotation of "ABCEFG"???! The fact that "GAB" is a substring of the
cyclic buffer is completely irrelevant.
No I am not suggesting this is the case, but that the poster did not specify
this to be the case. In fact the post is open to interpretation, it was
ambiguous at best.


Ah, OK. I'll give you that. A cyclic buffer/string (aka circular)
means something very specific to me, as does rotation.
In order for the input string to even be considered as a rotation of
the original string THEY BOTH MUST BE OF THE SAME LENGTH. The
algorithm takes care of that by making sure that they are. QED.

Yes Yes, I see what you are saying and in fact I also said you were correct
if this assumption stands, by the way, you dont need to capitalise youre
sentences in order for me to read them, I can read them just as well in
lower or proper case.


Sorry, I thought I was stating the bleedin' obvious... But if there
are different interpretations of the requirements, that may not be so.
:)

WMST RGDS, ;)

Nov 20 '05 #16
Thx Andy. This is a very good idea. However in my specific implementsion
this could lead to false positives:

String: 1 1 3 3
Double it: 1 1 3 3 1 1 3 3
IndexOf (3 3 1 3) = 3

Good thinking though, very clever :o)
"_Andy_" <wi******@nospamthanks.gov> wrote in message
news:96********************************@4ax.com...
On Fri, 21 Nov 2003 05:10:05 GMT, "Rogers" <al**********@msn.com>
wrote:
I want to compare strings of numbers that have a circular boundary
condition. This means that the string is arranged in a loop without an
end-of-string. The comparaison of two strings now becomes a different
operation than with regular strings because the circular string can be
"rotated", like this:

1 2 3 4 5
2 3 4 5 1
3 4 5 1 2
4 5 1 2 3
5 1 2 3 4

So under the "circular string comparator", all the above strings would be
equal.

I need to do a lot of those comparaisons so optimization is required. Whatis the fastest implementation possible in VB.NET? The strings have lenthsranging from 2 to ~100.

Any ideas?


Consider doubling the string.

i.e. 1 2 3 4 5 1 2 3 4 5
You will note that all rotations exist in this string. And if you
incorporate a length check, you get the desired result. Leading to:

Function StringMatch(find As String,source As String) As Boolean
If Len(find) = Len(source) And _
(source & source).IndexOf(find) <> -1 Then
Return True
Else
Return False
End If
End Function

Rgds,

Nov 20 '05 #17
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

Good idea anyways, clever :o)

Alain
"_Andy_" <wi******@nospamthanks.gov> wrote in message
news:96********************************@4ax.com...
On Fri, 21 Nov 2003 05:10:05 GMT, "Rogers" <al**********@msn.com>
wrote:
I want to compare strings of numbers that have a circular boundary
condition. This means that the string is arranged in a loop without an
end-of-string. The comparaison of two strings now becomes a different
operation than with regular strings because the circular string can be
"rotated", like this:

1 2 3 4 5
2 3 4 5 1
3 4 5 1 2
4 5 1 2 3
5 1 2 3 4

So under the "circular string comparator", all the above strings would be
equal.

I need to do a lot of those comparaisons so optimization is required. Whatis the fastest implementation possible in VB.NET? The strings have lenthsranging from 2 to ~100.

Any ideas?


Consider doubling the string.

i.e. 1 2 3 4 5 1 2 3 4 5
You will note that all rotations exist in this string. And if you
incorporate a length check, you get the desired result. Leading to:

Function StringMatch(find As String,source As String) As Boolean
If Len(find) = Len(source) And _
(source & source).IndexOf(find) <> -1 Then
Return True
Else
Return False
End If
End Function

Rgds,

Nov 20 '05 #18
Thanks you all for your help. What I implemented so far is listed below.
Despite the brute force approach, it's still acceptable till the strings are
about 1 K long. I didn't barther comparing character per character. I
think the bulk of the CPU cycles are being spent in the string manipulation.
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!

Anyways I don't think I can avoid goint to an Array representation of the
string since the real requirement really has 2D string with circular
bourdary condition (Spherical String) and 3D as well (Hyperspherical
Strings).

AL
Public Function CircStrComp(ByRef Str1 As String, ByRef Str2 As String)
As Boolean
' Using plain Strings
Dim TmpStr1 As String = Str2
Dim x As Integer

For x = 1 To TmpStr1.Length
If Str1 = TmpStr1 Then
Return True
Else
' Rotate String
TmpStr1 = TmpStr1.Remove(0, 1) & TmpStr1.Chars(0)
End If
Next
End Function

"_Andy_" <wi******@nospamthanks.gov> wrote in message
news:9k********************************@4ax.com...
On Fri, 21 Nov 2003 15:36:37 +0000 (UTC), "One Handed Man"
<Bo****@Duck.net> wrote:
_Andy_
Are you suggesting that "GAB" could in any way be considered a
rotation of "ABCEFG"???! The fact that "GAB" is a substring of the
cyclic buffer is completely irrelevant.


No I am not suggesting this is the case, but that the poster did not specifythis to be the case. In fact the post is open to interpretation, it was
ambiguous at best.


Ah, OK. I'll give you that. A cyclic buffer/string (aka circular)
means something very specific to me, as does rotation.
In order for the input string to even be considered as a rotation of
the original string THEY BOTH MUST BE OF THE SAME LENGTH. The
algorithm takes care of that by making sure that they are. QED.

Yes Yes, I see what you are saying and in fact I also said you were correctif this assumption stands, by the way, you dont need to capitalise youre
sentences in order for me to read them, I can read them just as well in
lower or proper case.


Sorry, I thought I was stating the bleedin' obvious... But if there
are different interpretations of the requirements, that may not be so.
:)

WMST RGDS, ;)

Nov 20 '05 #19
On Sat, 22 Nov 2003 02:47:01 GMT, "Alain" <al*********@msn.com> wrote:
Thx Andy. This is a very good idea. However in my specific implementsion
this could lead to false positives:

String: 1 1 3 3
Double it: 1 1 3 3 1 1 3 3
IndexOf (3 3 1 3) = 3
Eh? No it isn't. IndexOf 3313 = -1

Good thinking though, very clever :o)


The algorithm supplied sovles your problem, does it not? It has been
challenged, but no evidence has been provided to show that it doesn't
work. I have tried to demonstrate how it solves the problem, but even
that hasn't been read.

In summary, this is a very trivial problem (a common one at that) and
I'm a little bemused by it causing so much confusion. Perhaps it's the
alcohol, perhaps it's the fact that I have just watched the most
"Boring Rugby" in my life... and beating the Aussies. <g> ;)

Rgds,

Nov 20 '05 #20
On Sat, 22 Nov 2003 02:47:14 GMT, "Alain" <al*********@msn.com> wrote:
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 ---------------vSource: 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,


Nov 20 '05 #21
On Sat, 22 Nov 2003 02:47:01 GMT, "Alain" <al*********@msn.com> wrote:
Thx Andy. This is a very good idea. However in my specific implementsion
this could lead to false positives:

String: 1 1 3 3
Double it: 1 1 3 3 1 1 3 3
IndexOf (3 3 1 3) = 3
Eh? No it isn't. IndexOf 3313 = -1

Good thinking though, very clever :o)


The algorithm supplied sovles your problem, does it not? It has been
challenged, but no evidence has been provided to show that it doesn't
work. I have tried to demonstrate how it solves the problem, but even
that hasn't been read.

In summary, this is a very trivial problem (a common one at that) and
I'm a little bemused by it causing so much confusion. Perhaps it's the
alcohol, perhaps it's the fact that I have just watched the most
"Boring Rugby" in my life... and beating the Aussies. <g> ;)

Rgds,

Nov 20 '05 #22
On Sat, 22 Nov 2003 02:47:14 GMT, "Alain" <al*********@msn.com> wrote:
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 ---------------vSource: 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,


Nov 20 '05 #23
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
Nov 20 '05 #24

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Stéphane Ninin | last post by:
Hi all, This is not the first time I see this way of coding in Python and I wonder why this is coded this way: Howto on PyXML (http://pyxml.sourceforge.net/topics/howto/node14.html) shows it...
2
by: Zhaozhi Gao | last post by:
I'm doing a simple project for school. This is the first time I've ever used Access. Is there a way i can simulate a Circular Queue data structure for the datas in a table. I tried assign index...
2
by: Jon Davis | last post by:
The garbage handler in the .NET framework is handy. When objects fall out of scope, they are automatically destroyed, and the programmer doesn't have to worry about deallocating the memory space...
0
by: BBuff | last post by:
After running my site through the VS2005 RC Upgrade Wizard, I now have a ton of "Circular file references are not allowed" errors relating to my User Controls. Any idea on how to solve this as the...
3
by: Richard Lewis Haggard | last post by:
We are having a lot of trouble with problems relating to failures relating to 'The located assembly's manifest definition with name 'xxx' does not match the assembly reference" but none of us here...
2
by: danny.dion | last post by:
Hi ! I have a question about JScript : I have an object class wich dynamically creates a control in the page. Then it binds an event to that control, pointing on one of its methods (the...
2
by: Jeremy Kitchen | last post by:
I have inherited a project and I am trying to figure out why the failing units tests that exist fail. I a, getting the following error when I attempt serialization. Any advice on what I should...
3
by: =?Utf-8?B?UGF1bCBIYWxl?= | last post by:
Moving all User Controls to a single directory has solved my problem - Thanks Eliyahu. That said, I still got one Circular ref error yesterday, rebuilt again and the build was fine? Far far...
0
by: =?Utf-8?B?QmVybnJkIE5vcm1pZXI=?= | last post by:
The code in question is very simple: PACL acl = 0; PACL newAcl = 0; PSECURITY_DESCRIPTOR sd = 0; DWORD res = GetNamedSecurityInfo(const_cast<char*>(path.c_str()), type,...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.