473,783 Members | 2,418 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

FASTEST way to try all strings (a until ZZZZZZZZZZZZZZZ ZZZZZZZZZ)

Hi,

I need to find the FASTEST way to get a string in a Loop, that goes from "a"
to "ZZZZZZZZZZZZZZ ZZZ".
So it has to go like this:

a
b
....
z
A
....
Z
aa
ab
....
az
aA
....
ZZZZZZZZZZZZZZZ ZZZZZZZZZZZZZZZ ZZZZZ

So it has to try every combination with all the 26 letters, making a
difference between upper case and lower case, and the space (" ") has to be
included too.

Does anybody knows a way to do this?
I do not need this to hack any password or stuff liek this: I'm working with
the SDK of the Belgian governemnet for the electronic identity card. For
some @%£&§*$!! reason these guys made some big mistakes in there
documentation, and used the parameters with the info on a stupid way. Half
of them aren't working.... So the only ways to find out the missing
paramters is:
1. ask them for info, but they seem to be to stupid to knwo anything about
the stuff they made themselves...
2. Try avery combination of letters... So that's what I want to do :-)
I came up with this: but it doesn't work as fast as I want to...

dblBegin = 0
dblEnd = 52 ^ 30
For dblTeller = dblBegin To dblEnd
strT = GiveWord()
TestValue(strT)
txtWord.Text = strT
Application.DoE vents()
Next
Private Function GiveWord() As String
Dim strA As String = ""
Dim dblRest As Double
Dim dblQuotient As Double
dblQuotient = dblTeller
Do
dblRest = dblQuotient Mod 53
'1-26 = a-z
'27-52 = A-Z
If dblRest = 0 Then
dblRest = 32 'space
ElseIf dblRest < 27 Then
dblRest = dblRest + 96
Else
dblRest = dblRest + 38
End If
strA = Chr(dblRest) & strA
dblQuotient = dblQuotient \ 53
Loop Until dblQuotient = 0
GiveWord = strA
End Function
Jul 21 '05
17 2331
Jay B. Harlow [MVP - Outlook] <Ja************ @msn.com> wrote:
Yes - because it doesn't require creating an extra string each time.
The StringBuilder contains a string which is mutable until you call
ToString on it. Its the "mutable until you call ToString" part that "confuses" me, hence my
question.

Presumably you would need to call StringBuilder.T oString on each iteration,
as you want to pass the string to another function.
Yup.
Does the StringBuilder then need to create a new buffer (aka a new "string")
so that you can modify the char, or does it simply call New String(char[]) &
copy the existing buffer.
ToString itself doesn't create a new buffer; when you next modify the
data it creates a new copy.
I was under the impression that it will create a new buffer when you modify
the StringBuilder after calling ToString (copy on write, not copy on read).


Yup. I wasn't quite clear - sorry about that.

I guess it ends up being the same as creating a new string from a char
array, keeping the char array between iterations. Sorry - can't have
been thinking properly :(

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #11
Jon,
ToString itself doesn't create a new buffer; when you next modify the
data it creates a new copy. OK, that's what I was thinking.

I guess it ends up being the same as creating a new string from a char
array, keeping the char array between iterations. Sorry - can't have
been thinking properly :( I was asking more "stylistica lly" rather then performance. :-)

The OP would really need to profile it to see which performed better. I
would also watch what impact both had on the GC (I would expect about the
same, as the "buffer" itself should be static.)

Granted this is a somewhat limited scenario, I was just curious what you or
others thought...

Thanks for the info, I knew StringBuilder.T oString was "special", I just
didn't remember...

Thanks
Jay

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com... Jay B. Harlow [MVP - Outlook] <Ja************ @msn.com> wrote:
> Yes - because it doesn't require creating an extra string each time.
> The StringBuilder contains a string which is mutable until you call
> ToString on it.

Its the "mutable until you call ToString" part that "confuses" me, hence
my
question.

Presumably you would need to call StringBuilder.T oString on each
iteration,
as you want to pass the string to another function.


Yup.
Does the StringBuilder then need to create a new buffer (aka a new
"string")
so that you can modify the char, or does it simply call New
String(char[]) &
copy the existing buffer.


ToString itself doesn't create a new buffer; when you next modify the
data it creates a new copy.
I was under the impression that it will create a new buffer when you
modify
the StringBuilder after calling ToString (copy on write, not copy on
read).


Yup. I wasn't quite clear - sorry about that.

I guess it ends up being the same as creating a new string from a char
array, keeping the char array between iterations. Sorry - can't have
been thinking properly :(

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Jul 21 '05 #12
Jay B. Harlow [MVP - Outlook] <Ja************ @msn.com> wrote:
Jon,
ToString itself doesn't create a new buffer; when you next modify the
data it creates a new copy. OK, that's what I was thinking.
I guess it ends up being the same as creating a new string from a char
array, keeping the char array between iterations. Sorry - can't have
been thinking properly :(

I was asking more "stylistica lly" rather then performance. :-)


In that case I'd probably go for the char array.
The OP would really need to profile it to see which performed better. I
would also watch what impact both had on the GC (I would expect about the
same, as the "buffer" itself should be static.)
Yep, likewise. Indexing an array is probably quicker than indexing a
StringBuilder though.
Granted this is a somewhat limited scenario, I was just curious what you or
others thought...

Thanks for the info, I knew StringBuilder.T oString was "special", I just
didn't remember...


It's a bit of a shock when you first find out that strings are really
mutable, isn't it?

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #13
Jay,

I was first going for the arraylist and the the stringbuilder as forever as
you know, however

Pieter told a to z and A to Z and space, that can be done as bytes
97 to 122 and 65 to 90 and 32.

Pieter lives in Belgium which has the same code set as you and me and he
told this explicitly because in Belgium is spoken Dutch and French (a very
small minority German) and the French uses a lot of characters which are not
ASCII however as far as I know in the standard 255 set (maybe can Pieter
tell that).

He told only the characters in the ASCII range so you can be sure that he as
a Belg did that explicitly.

It will be a very huge table so I in my opinion. I once did a test between a
stringbuilder against a bytearray (however silly one because it needed
chars, but somebody told his routine was faster so I made that to tell that
everything can go faster) where the bytearray was twice as fast.

There is in this case for sure only one byte needed instead of two. The only
place you loose some bytes against the characterstring is as far as I can
see when there are spaces at the end, however that will be a minority and
everytime less.

When it would be used, than it should be converted to a string, however
that can even with ASCII in this case. (And this is probably an exception
where this just fit)

I think it will not be that big difference with you method at the moment, it
uses at least than less memory I think and probably go faster.

However just what I thought, never tested, so when I have made mistakes in
this, tell it.

:-)

Cor
"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com>
Cor,
How would saving 17 bytes really be saving anything?

How would an array of Byte be any faster then an array of Char? Especially
when I would expect the function that the OP is calling needs a String? I
agree if the OP's function needed an array of Byte, then an array of Byte
is needed, however the OP suggested Chars (A to Z, a to z and space).

My routine works directly with Unicode Chars there is no encoding involved
(an array of Byte would need an "expensive" Encoding object to convert
from Bytes to Chars or String.

Just curious where you are coming from.

Jay

"Cor Ligthert" <no************ @planet.nl> wrote in message
news:Om******** ******@TK2MSFTN GP10.phx.gbl...
Jay B.

I think that an array of bytes would in this case be the fastest and also
would help to minimize the used space.

Cor


Jul 21 '05 #14
Cor,
It will be a very huge table so I in my opinion. If the OP is going to keep all or most of the entries in a table at one
time, then yes Bytes may be better.

However! I was going on creating one "value" & using it at a time. In which
case 17 Bytes is no "better" then 17 Chars...

Thanks for the additional
Jay

"Cor Ligthert" <no************ @planet.nl> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. .. Jay,

I was first going for the arraylist and the the stringbuilder as forever
as you know, however

Pieter told a to z and A to Z and space, that can be done as bytes
97 to 122 and 65 to 90 and 32.

Pieter lives in Belgium which has the same code set as you and me and he
told this explicitly because in Belgium is spoken Dutch and French (a very
small minority German) and the French uses a lot of characters which are
not ASCII however as far as I know in the standard 255 set (maybe can
Pieter tell that).

He told only the characters in the ASCII range so you can be sure that he
as a Belg did that explicitly.

It will be a very huge table so I in my opinion. I once did a test between
a stringbuilder against a bytearray (however silly one because it needed
chars, but somebody told his routine was faster so I made that to tell
that everything can go faster) where the bytearray was twice as fast.

There is in this case for sure only one byte needed instead of two. The
only place you loose some bytes against the characterstring is as far as I
can see when there are spaces at the end, however that will be a minority
and everytime less.

When it would be used, than it should be converted to a string, however
that can even with ASCII in this case. (And this is probably an exception
where this just fit)

I think it will not be that big difference with you method at the moment,
it uses at least than less memory I think and probably go faster.

However just what I thought, never tested, so when I have made mistakes in
this, tell it.

:-)

Cor
"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com>
Cor,
How would saving 17 bytes really be saving anything?

How would an array of Byte be any faster then an array of Char?
Especially when I would expect the function that the OP is calling needs
a String? I agree if the OP's function needed an array of Byte, then an
array of Byte is needed, however the OP suggested Chars (A to Z, a to z
and space).

My routine works directly with Unicode Chars there is no encoding
involved (an array of Byte would need an "expensive" Encoding object to
convert from Bytes to Chars or String.

Just curious where you are coming from.

Jay

"Cor Ligthert" <no************ @planet.nl> wrote in message
news:Om******** ******@TK2MSFTN GP10.phx.gbl...
Jay B.

I think that an array of bytes would in this case be the fastest and
also would help to minimize the used space.

Cor



Jul 21 '05 #15
Jon,
It's a bit of a shock when you first find out that strings are really
mutable, isn't it?
Check out:

MarshalAs(Unman agedType.VBByRe fStr)

It allows VB.NET to declare P/Invoke functions such that the String (yes
System.String) itself is modified during the P/Invoke call.

Its mentioned briefly in Adam Nathan's book ".NET and COM - The Complete
Interoperabilit y Guide" from SAMS press, with caveats.

Jay

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com... Jay B. Harlow [MVP - Outlook] <Ja************ @msn.com> wrote:
Jon,
> ToString itself doesn't create a new buffer; when you next modify the
> data it creates a new copy.

OK, that's what I was thinking.
> I guess it ends up being the same as creating a new string from a char
> array, keeping the char array between iterations. Sorry - can't have
> been thinking properly :(

I was asking more "stylistica lly" rather then performance. :-)


In that case I'd probably go for the char array.
The OP would really need to profile it to see which performed better. I
would also watch what impact both had on the GC (I would expect about the
same, as the "buffer" itself should be static.)


Yep, likewise. Indexing an array is probably quicker than indexing a
StringBuilder though.
Granted this is a somewhat limited scenario, I was just curious what you
or
others thought...

Thanks for the info, I knew StringBuilder.T oString was "special", I just
didn't remember...


It's a bit of a shock when you first find out that strings are really
mutable, isn't it?

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Jul 21 '05 #16

"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote
Granted this is a somewhat limited scenario, I was just curious what you or
others thought...


I had a go at it, using this code:

LFS

Dim chars(19) As Char
Dim tbl(255) As Integer
Dim itm, ch As Integer

chars.Initializ e()
For ch = 0 To 19
chars.SetValue( " "c, ch)
Next
chars.SetValue( "a"c, 19)

For ch = 1 To 255
tbl(ch - 1) = ch
Next
tbl(33) = 97
tbl(123) = 65
tbl(92) = 32

Do
Label1.Text = CType(chars, String)
Label1.Refresh( )

ch = tbl(Asc(CType(c hars.GetValue(1 9), Char)))
If ch = 91 Then
itm = 19
Do While ch = 91
chars.SetValue( "a"c, itm)
itm -= 1
If itm = 0 Then Exit Sub
ch = tbl(Asc(CType(c hars.GetValue(i tm), Char)))
chars.SetValue( Chr(ch), itm)
Loop
Else
chars.SetValue( Chr(ch), 19)
End If
Loop

Jul 21 '05 #17

"Larry Serflaten" <se*******@usin ternet.com> wrote
tbl(33) = 97
tbl(123) = 65
tbl(92) = 32


Wrong values! (oops)

S/B

tbl(32) = 97
tbl(122) = 65
tbl(91) = 97

(Drats!)
LFS
Jul 21 '05 #18

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

Similar topics

17
1212
by: DraguVaso | last post by:
Hi, I need to find the FASTEST way to get a string in a Loop, that goes from "a" to "ZZZZZZZZZZZZZZZZZ". So it has to go like this: a b .... z
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10313
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10081
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9946
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8968
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3643
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2875
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.