|
yes andi normally use the split function for example
if i hava a string="walk,keny,go"
i will get all off the values like walk or kenny or go by setting the delimeter to ","
but supposei have a string="lets walk to the suppermarket"
is there anyway for me to access each character by themself for example i know if i was puting this in an array. array[o] would be l and array[1] would be e
???? u have any idea how i could do this? or any link to any example if it might be too tediuos to show me how to do it?????
beginner c#
|
|
|
|
|
You could use String.ToCharArray() or maybe simply call String.SubString(index, index+1).
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
www.troschuetz.de
|
|
|
|
|
what would index and index+1 be for example string.substring(0,1) and this will return the first and second element??
|
|
|
|
|
Ups, I didn't look hard enough at the docs. First parameter is the startIndex, so if you want the "l" from your example string it should be 0. Second paramter is length, so it has to be 1.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
www.troschuetz.de
|
|
|
|
|
Thanks it works perfectly
kenny
|
|
|
|
|
Does it have to be a string array, if you're only using single characters then the string.ToCharArray() will do it exactly. But if you want to use strings then I think you will have to write a loop which walks through, adding them to a list as it goes.
You know you're a Land Rover owner when the best route from point A to point B is through the mud.
Ed
|
|
|
|
|
i would prefer it to prob be a string because as i go alopngiwant to tets my data to see what is bieng saved but everytime i try to set a textboxt.text=charArray[0] i get an error saying char cannot be converted to string
hence if it was stored in a string array i cold prob display it in the textbox or i dont know if is the way i am trying to display it is wrong.
is there a way display char in your textbox
do u have any samples onlinei could look on that shows u how to loop through a string character by character
kenny
|
|
|
|
|
keroed_edmond wrote: textboxt.text=charArray[0]
Try
textboxt.text=charArray[0].ToString();<br />
<br />
:doh:<br />
You know you're a Land Rover owner when the best route from point A to point B is through the mud.
Ed
|
|
|
|
|
You don't have to convert the string at all to access the separate characters. Just use an index to access the characters:
string message = "So long and thanks for all the fish.";<br />
char c1 = message[0];
char c2 = message[35];
You can easily convert a char to a string:
string s1 = new string(c1);
string s2 = new string(c2);
There are many ways to get a single character from a string into a new string. Here are some:
textbox.Text = new string(message[0]);<br />
textbox.Text = message.SubString(0, 1);<br />
textbox.Text = new string(message.ToCharArray()[0]);<br />
textbox.Text = new string(message.ToCharArray(), 0, 1);<br />
textbox.Text = new string(message.ToCharArray(0, 1));<br />
textbox.Text = new string((char)(new StringReader(message).Read()));
---
b { font-weight: normal; }
|
|
|
|
|
Bit of an overkill for what he wants.
You know you're a Land Rover owner when the best route from point A to point B is through the mud.
Ed
|
|
|
|
|
Yes, of course some of the alternatives are. I just thought that I'd show that there is more than one way to skin a cat.
Anyway, I'm not really sure what he wants, and frankly I don't think he is either...
---
b { font-weight: normal; }
|
|
|
|
|
keroed_edmond wrote: textboxt.text=charArray[0]
Based on that, I think he just wants to display the first character in the array.
You know you're a Land Rover owner when the best route from point A to point B is through the mud.
Ed
|
|
|
|
|
|
vernchen wrote: you can use split(',');
Not unless there are comma's seperating all characters If you look at the above thread you'll see that what he needed was the ToString() method
You know you're a Land Rover owner when the best route from point A to point B is through the mud.
Ed
|
|
|
|
|
You can treat a regular string like a char array and just index it:
string mystring = "hello";
char h = mystring[0];
|
|
|
|
|
With an Installer class, I am overriding the Install() function.
I have read that throwing an InstallException() from within my installer DLL code, will force the setup project install to fail and cause setup to rollback.
But this causes an ugly dialog to pop up and inform the user that an exception has been thrown.
I am wondering if there is another (cleaner) way to cause the Install() to fail, and there for RollBack()?
Thanks folks.
-- modified at 16:49 Wednesday 7th June, 2006
|
|
|
|
|
Hi there, can anyone help me understand how it's possible to generate a keypair using .net 2.0 and have the private key secured with a passphrase?
Thanks
Clonus
|
|
|
|
|
Clonus wrote: generate a keypair using .net 2.0
You create a keypair by creating a new instance of the RSACryptoServiceProvider class (key size can be specified in constructor), once created you can then access the keys either through the ToXmlString method or through ExportParameters (specifying the whether to include the private keys).
Clonus wrote: private key secured with a passphrase
To do this you can use DESCryptoServiceProvider which accepts a key (but it must be a strong key) to encrypt data. To create a strong key you could use the PasswordDeriveBytes class which can take a password string and a collection of random bytes and generate a key out of this. Take a look at this article[^] on MSDN which will show how to use it. You're only solution if you go down this road is to use constant (or calculable) "salt" bytes. Perhaps the simplest (although not cryptographically secure) is to generate some random bytes once and then use these in all instances as the "salt" bytes.
There may be better ways around this but atleast these methods use the .NET Framework classes. You're welcome to write your own encryption algorithm for the password storing of the private key. It all depends on how secure you need it.
You know you're a Land Rover owner when the best route from point A to point B is through the mud.
Ed
|
|
|
|
|
Thanks for the link Ed, however, I'm not sure how this would apply to RSA?
The example uses TripleDES, and it seems I've been playing around with this code and haven't been able to generate a public and encrypted private key yet.
Is this specific to DES only?
Sorry, "me brain just don't register this" !
|
|
|
|
|
You see, generating the public and private keys is very simple with RSA but using a passphrase on the private key of this pair is what I am trying to accomplish.
I can't seem to find any information on how to do this?
|
|
|
|
|
It all depends on how secure you want it.
Basically RSA uses a random key which must be strong, it's best to leave this to be generated by the cryptographic system. For more "classic" password protection schemes you can use DES (Triple or some other variant) which takes a single encryption key, this key is used to encrypt and decrypt the data (unlike the public key used in RSA to encrypt and the private to decrypt). The key used by DES must be a "strong" key, i.e. cryptographically strong (so it's not easy to break), the .NET Framework implementation does not allow encryption with weak keys, an exception is thrown. Normally this key is an array of random bytes. But by using the PasswordDeriveBytes class you can generate these random bytes from a password string.
The PasswordDeriveBytes constructor takes a password string and some "salt" bytes, these bytes are intermingled in the key generated at (probably) random but calculable locations. So essentially it takes your password string, converts it to bytes, adds the salt bytes and mixes them up in a particular way, probably based on the values of the password bytes.
So essentially what you need to do is:
- Generate the public and private key from the
RSACryptoServiceProvider . - Select a password and use
PasswordDeriveBytes to generate a strong DES key. - Using
DESCryptoServiceProvider encrypt the private key of the RSA Key Pair with the bytes generated in step 2. - Do what you want
What I mentioned in the previous reply was that the "salt" bytes must be consistent or calculable from the password string, it's no use using different salt-bytes for the same password string because you won't get the same key so you can't decrypt the private key for the RSA algorithm.
- The simplest would be to generate some random bytes once and hard-code these into your application as the salt-bytes. This however is not very secure or wise.
- The better way to accomplish this would be to write an algorithm (or find one) than generates some random bytes based on the password string, this would mean that the string changes each time the password changes but remains the same for the same password.
Neither of these methods would be very secure since in a) the bytes are hard-coded and easily extractable using Reflector. In b) they are not so extractable since they are hidden by an algorithm it all depends on how confusing this algorithm is to interpret as to how easy it is to break the system (because once they have the bytes then they can plug them back into the PasswordDeriveBytes class and get your key back).
It's all (as will all cryptography) a matter of complexity verses security.
You know you're a Land Rover owner when the best route from point A to point B is through the mud.
Ed
|
|
|
|
|
I'm trying to list all members of a COM class that I load using GetTypeFromProgID.
I'm using GetMembers() but I can't see the classes members except for the base members.
How can I achieve this? Is there an alternative way?
Thank you
|
|
|
|
|
I have been reading many of the examples of how to create a progress bar, but none of them have helped me solve my problem... To simplify my problem I have two projects in my solution. One for the User Interface (UI), and one for the Business objects (BO). I need to have a way to update a progress bar in my UI project from my BO project. My UI project references the BO project, so I have to make sure to avoid circular references.
All of the examples I have found have all the code in the same project.
Please help!
Hogan
|
|
|
|
|
In your BO project:
Take the class that contains the method of which you want to track the progress and an event named ProgessChanged or something similar. Inside the method of which you want to track the progress raise this event whenever a specific progress is made or maybe after some fix interval and pass a custom EventArgs object containing a progress estimation.
In your UI project:
Subscribe to the ProgressChanged event and inside the event handler update your progress bar.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
www.troschuetz.de
|
|
|
|
|
Hello all, I seem to be having a small problem killing threads in a console application.
The symptoms of the problem is that the application never exits, and I can only assume that this is due to a threading issue.
I currently have the following (edited for simplicity) code:
int threadTimeout = 2000;
for (int loop=0; loop < syncServers.Length; loop++)
{
this.syncServer = syncServers[loop];
Thread syncThread = new Thread(new ThreadStart(DoSync));
syncThread.Start();
Thread.Sleep(threadTimeout);
if (syncThread.IsAlive)
{
syncThread.Abort()
}
}
private void DoSync()
{
DoTimeSync(this.syncServer)
}
Now lets say that syncServers has three items, the code cycles through each one waiting for the timeout. However when the last one completes the application just hangs, I would expect it to close (there is no further code after the end of the for loop)
EDIT : Just for clarity, the reason I am doing this is that I am using UDP to perform time synchronisation requests, unfortunatly the .NET 1.1 UDP listener doesnt support a timeout and if the sync server doesnt exisit the UDP listener sits and waits for ever.
EDIT 2 : I have also try using:
if (syncThread.ThreadState != ThreadState.Stopped)
{
syncThread.Abort()
}
|
|
|
|