|
Hi all
I have a DateTimePicker control in my windows application(c#)
am taking the selected value from the DateTimePicker to a textbox...now am getting the value
in the format of ' dd-mm-yyyy ' but i want to get the value like ' dd/mm/yyyy '...
i have given all these..
dateTimePicker1.CustomFormat = "dd/MM/yyyy";
dateTimePicker1.Format = DateTimePickerFormat.Custom;
txtdate.Text = dateTimePicker1.Value.ToShortDateString();
how can get the value like which i have mentioned...
any help is appreciatable....
thanks in advance...
|
|
|
|
|
txtdate.Text = dateTimePicker1.Value.ToShortDateString().Replace("-", "/");
That should do the trick.
Kinda ugly, but it should work.
Kristian Sixhoej
|
|
|
|
|
Thanks Kristian...
It wrked well....
|
|
|
|
|
Kristian Sixhoej wrote: Kinda ugly, but it should work.
This is really ugly. What's wrong with using ToString() with a proper format specifier?
modified 12-Sep-18 21:01pm.
|
|
|
|
|
You have half the answer yourself - you know the format and how to specify. What you may not know is that dateTime has an override of ToString which can take this format.
txtdate.Text = dateTimePicker1.Value.ToString("dd/MM/yyyy");
|
|
|
|
|
This should work
txtdate.Text = dateTimePicker1.Value.ToString("dd/MM/yyyy");
Hope this helps
|
|
|
|
|
hi....
actually am doing a simple application using
" WCF Service Application " & " ASP.NET Web Application "..........
my code is correct and everything is perfect..
but when i run, it displays the following message....
" An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue "
when i run in the morning the output is displayed..but after sometime , when i run it shows that message.....
whats the solution...??...
|
|
|
|
|
Looks like you are running out of resources.
Just a thought: Are you cleaning up the resources you are using? Do you have a lot of objects that implement the IDisposable interface that you are not disposing correctly?
|
|
|
|
|
So I read a file and that file has like 9k lines.
the lines look like this(well it might not fit here, but is on a line only):
A:"extatic" A:"extatici" A:"extaticul" A:"extaticului" A:"extaticii" A:"extaticilor" A:"extatică" A:"extatice" A:"extatica" A:"extaticei" A:"extaticele" A:"extaticelor"
And I use textreader in c# to find a char in that text for example "extaticele" here.
What I want is to extract if I found the char on that line the first char on that line. In this case "extatic" - but without "" of course and paste it in a text file.
I dont know exactly how to work with find space so I want your help...cause I thought I'd find the first space in the line then take the index and with the index 0 of the line to extract "A:"extatic" ".
Then remove the "A:" and the ".
I saw somewhere an example with myString.find("") , but I can't find the "find" I might need a namespace.
|
|
|
|
|
In .Net, reference types are also objects. That means that most of the commands that you are looking for are present in the string itself. You can play with stuff like:
String test = "abcd";
int index = test.IndexOf('b');
String test2 = test.Substring(index);
// etc...
There are plenty of methods on the string object. There are also static methods in the String class, like for example:
String.Compare(string1, string2...)
Last but not least, the namespace you are looking for is simply System.
Jean-Christophe Grégoire
|
|
|
|
|
I use that namespace, but there is no mystring.Find - I just want to find the index of the first space in a line
|
|
|
|
|
ipstefan wrote: I use that namespace, but there is no mystring.Find - I just want to find the index of the first space in a line
int index = myString.IndexOf(" ");
Kristian Sixhoej
|
|
|
|
|
Yep I thought at that option too earlier and it works...
I solved my problem with indexes and substrings.
Thanks
|
|
|
|
|
You're welcome
Kristian Sixhoej
|
|
|
|
|
hi ipstefan,
my sugession is read contents of file sequentially and check whether the character u r reading is ", it it is then take all next characters untill next " apprears so u can get each character between "". From these chars u can make a string by using + operator and later it can be pasted where u want.
Or as u mentioned myString.find() method, i hope find method is custom method not in framework. Instead, u can use following method of class String.
String myString = "abcd";
String cutString = myString.Substring(0,3);
the value of cutString will be 'abc' . Try to use this method. Ok..
Hope it will help u.
|
|
|
|
|
Dear all,
I am working on C# project, which need to digital sign on all data (string DataType). I have .pfx (X509) file already (contain public key + private key). Is there anyway to pass the private key + public key in .pfx file to DSA, to create digital signature ?
Below is the code in JAVA, which I think use DSA in C# may create the digital sign exactly this java code.
Many thank if you can help.
//---------------------- JAVA DIGITAL SIGN CODE ---------------------
private static void readPrivateKeyAsClassPath() {
try {
// Read key
InputStream fis = SignatureDegist.class.getResourceAsStream("/"
+ keyFile);
ObjectInputStream ois = new ObjectInputStream(fis);
priv = (PrivateKey) ois.readObject();
ois.close();
} catch (Exception e) {
}
}
/**
* @param filename
* @throws FileNotFoundException
* @throws IOException
* @throws ClassNotFoundException
*/
private static void readKeysPrivateKey(String filename)
throws FileNotFoundException, IOException, ClassNotFoundException {
if (priv == null) {
setKeyName(filename);
readPrivateKeyAsClassPath();
}
}
private static byte[] sign(InputStream reader, String sigAlg)
throws Exception {
Properties pro = new Properties();
pro.load(SignatureDegist.class.getResourceAsStream(CONFIG_KEY_FILE_LOCATION));
if (priv == null) {
readKeysPrivateKey(pro.getProperty("filename"));
}
Signature sig = Signature.getInstance(sigAlg);
sig.initSign(priv);
byte[] dataBytes = new byte[1024];
int nread = reader.read(dataBytes);
while (nread > 0) {
sig.update(dataBytes, 0, nread);
nread = reader.read(dataBytes);
}
;
return sig.sign();
}
private static byte[] sign(String datafile, String sigAlg) throws Exception {
return sign(new ByteArrayInputStream(datafile.getBytes()), sigAlg);
}
public static void main(String[] unused) throws Exception {
// Generate a key-pair
String accountIdSource = "123100003456";
String accountIdDest = "456100014123";
long value = 100;
String desc = "transfer";
String contactID = "NHK-XJ";
String typeId = "00";
StringBuffer buffer = new StringBuffer();
buffer.append(accountIdSource);
buffer.append(accountIdDest);
buffer.append(value);
buffer.append(desc);
buffer.append(contactID);
buffer.append(typeId);
byte[] degist = sign(buffer.toString(), "SHAwithDSA");
System.out.println("Signature degist :: " + degist);
System.out.println("Signature degist :: " + new String(degist));
Base64 decoder = new Base64();
System.out.println("Signature degist :: " + new String(decoder.encode(degist)));
System.out.println("Signature degist :: " + new String(decoder.encode(new String(decoder.encode(degist)).getBytes())));
|
|
|
|
|
Hello,
a 3rd party supplier informs me their components are compiled for "ANY CPU", so they'll run x86 or x64 based on the platform to which they're deployed. This confuses me a bit; I had thought a select choice of x64 compilation would ensure the best performance, which is why so many companies these days deliver product-installers for both x86 and x64. But if I'm to take his word for good measure, there's no need (at least .net-wise) to ever compile to a specific CPU architecture, as the "ANY CPU" option will always ensure the assemblies run as fast as possible, given the host CPU?
Hope someone might be able to clarify on this,
thanks in advance,
Morten
|
|
|
|
|
The Any CPU option is not optimised for a specific processor. It will give you good general all round performance that works across any of the target processors. If you absolutely must have all the performance you want then target the appropriate processor.
[ADDITIONAL]
First Addition::
There seems to be a lot of confusion about this. MSDN says one thing. The C# compiler command line help says another.
Second Addition:
See Guffa's post as he links to an article that explains exactly what is happening, and contradicts the MSDN article I used as the source of my original answer.
[/ADDITIONAL]
modified on Friday, January 9, 2009 1:24 PM
|
|
|
|
|
Hello Colin,
this was also my impression. Thanks a lot for clearing this up for me.
best,
Morten
|
|
|
|
|
harleydk wrote: Hello Colin,
this was also my impression. Thanks a lot for clearing this up for me.
Then your impression was also wrong.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Colin Angus Mackay wrote: It will give you good general all round performance that works across any of the target processors. If you absolutely must have all the performance you want then target the appropriate processor.
That is not correct. The IL code generated is the same regardless of which CPU target you specify.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
|
I saw that one. It doesn't go ino any depth, and I don't think that it's correct. Have a look at this, for example:
Visual Studio .NET Platform Target Explained[^]
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
The IL code in your assembly isn't specific to any processor at all. Regardless of what CPU target you choose, the IL code could still be used on any processor. The CPU target is simply information that the code should only be allowed to be used on a specific type of CPU.
You can use the CPU target for example to specify that your assembly only can be used in x86 mode as you are calling methods in an unmanaged x86-dll.
It's the JIT compiler that creates the machine code from the IL code when your assembly is loaded. It can create different code depending on the actual processor that will run the code, so that it will take advantage of the capabilities or that specific processor.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Guffa wrote: The IL code in your assembly isn't specific to any processor at all.
That was also my thought until the OP asked the question and it got me thinking. I then looked at MSDN and this article suggests (although not explicitly to do with the IL output) otherwise: http://msdn.microsoft.com/en-us/library/5b4eyb0k.aspx[^]
|
|
|
|