|
DateTime.ToString has an overload which takes a format string. The .NET docs list the format strings for dates. That should be what you need.
Josh
|
|
|
|
|
One way is this:
string date = "12/05/2006";
DateTime newDate;
if (DateTime.TryParse(date, out newDate))
{
DateTimeFormatInfo myDTFI = new CultureInfo("en-US", false).DateTimeFormat;
Console.WriteLine(newDate.ToString("MM/dd/yyy", myDTFI));
}
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Hi, this is the code i've been trying to convert from VB6 to C#...Is there any way to avoid reading every field of the struct and reaing the whole thing?
VB6 code:
--------------------------------------------------------
Type Person
sName as String * 12
Age as Byte
Code as Long
End Type
private persons() as Person
Sub LoadData(path As String)
dim hf as long
hf = FreeFile
dim recs as long
dim offset as long
open path for binary access read lock write as #hf
get #hf, 1, recs
get #hf, , offset
if recs > 0
redim persons(1 to recs)
'' Very easy way to retrieve UDT array data
get #hf, offset + 1, persons()
end if
End Sub
C#:
-------------------------------------------------------
using System;
using System.IO;
using System.Runtime.InteropServices;
//[StructLayout(LayoutKind.Sequential)]
public struct Person
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 12)]
string Name;
byte Age;
int Code;
}
public class PersonReader
{
private Person[] persons;
private void LoadData(string path)
{
Stream fileContents = File.Open(path, FileMode.Open);
BinaryReader binReader = new BinaryReader(fileContents);
int recs = binReader.ReadInt32();
int offset = binReader.ReadInt32();
binReader.BaseStream.Position = offset;
//Something like this should go here:
persons = binReader(...//read till the eof and convert it to Person[] :P
// Instead of a code that reads each data of the struct
binReader.Close();
fileContents.Close();
}
}
|
|
|
|
|
I need code that detects if a program is running and then opens a form.
ex.
You turn on your computer and a program starts to run in the background.
You open the internet and a form from the program that is already running opens with it.
Can anyone help me?
Thanks
Hengy
I like Pie
|
|
|
|
|
You might want to have a Windows Service running in the background, periodically polling Process.GetProcesses to see if a browser has been opened. When it detects a browser has been opened, open your Form. I know that there is some trickiness to getting a Form to appear from a windows service, but there should be an article on CP which explains how to do it.
Josh
|
|
|
|
|
Hi,
How can i sort dates In Ascending which look like this:
20060503
20060604
20080101
The first 4 digits is the year, the 2 after year are the months and the last 2 digits is the day.
It should first put them in an array, sort them and than display them in the console.
Thanks in advance!
|
|
|
|
|
Read each date string into a DateTime object. Put the DateTime objects into an array or some other container which exposes a Sort method (Array.Sort is static). Then loop over the array to print them out.
Josh
|
|
|
|
|
Hi Josh Smith,
Im not that good in programming yet. Do you have a sample code for me?
Thanks in advance!
|
|
|
|
|
Noone is going to write your homework for you.
|
|
|
|
|
How rude!
Like this is my homework :S
Seriously dan, where did you get that idea?
Im not that far yet at school. Im not even the one who's writing all this.
|
|
|
|
|
If it looks like a duck, walks like a duck, and quacks like a duck...
|
|
|
|
|
It's a duck!
|
|
|
|
|
Because of the formats, you can also put them in a List<string> and call .Sort().
|
|
|
|
|
Hi
I need a bit of help.
I have this string: "10 > 8 > 99> 34"
From this string, how can I extract all the numbers?
Basically, when I receive the above string, I want to get every number out of it and do something with that number.
Thanks
|
|
|
|
|
string[] numberstrings = mystring.split('>');
int[] numbers = new int[numberstrings.Length];
for (int i=0; i<numberstrings.Length; i++)
{
numbers[i] = int.Parse(numberstrings[i]);
}
You might want to make sure that all the strings that come out of the split really are numbers through so you should probably wrap the line in the for loop with a try/catch statement to be safe.
-- modified at 10:52 Monday 5th June, 2006
|
|
|
|
|
Hello!
I am trying to use GZipStream to compress an XML file before writing it to disk. But unfortunately it doesn't work 100% correctly... The file written to disk is a valid GZ file up to the very last few bytes. The whole file can be decompressed without any problems, except that the very last few bytes are broken and get decompressed incorrectly...
My code basically looks like this:
FileStream fs = new FileStream(strFilePath, FileMode.Create, FileAccess.Write, FileShare.None);
Stream writerStream = new GZipStream(fs, CompressionMode.Compress);
XmlTextWriter xtw = new XmlTextWriter(writerStream, Encoding.UTF8);
WriteDocument(xtw);
xtw.Flush();
writerStream.Flush();
fs.Flush(); fs.Close();
Files mostly get decompressed incorrectly like this (_ are spaces):
________</Group>
____</Group>
</Root>
</SplConfFile5ile5ile5ile5ile5ile5ile5ile5ile5ile5ile5ile5ile5ile5ile5il
Do you have any idea what could be the problem? Why are the very last few bytes corrupted?
Best regards
Dominik
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
(doesn't work on NT)
|
|
|
|
|
I've found the problem now. There is a bug in the GZipStream class of .NET 2.0 (yes, in the class, not in my code). You need to close the GZipStream manually...
For more details see this bug report at MSDN Product Feedback Center:
http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx?feedbackid=efaebf8f-8b1c-45e1-b355-6c6953aa221a[^]
I wonder why they released .NET 2.0 with such a long-known, serious bug...
Best regards
Dominik
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
(doesn't work on NT)
|
|
|
|
|
hi
when we press alt+shift inside textboxes, we convert to the second
keyboard language . what i want is to do this programmatically
i.e directly start writing in the second language
Tamimi - Code
|
|
|
|
|
You might be able to accomplish this by calling the SendKeys.Send method, passing a string which represents Alt + Shift. The docs for that method explain the symbols used to represent those non-alphanumeric keys.
Josh
|
|
|
|
|
HI!
I want to integrate some of VOIP applications in my .NET application.I have infos like email, mobile, telephone and I want to start a 3rd party VOIP application with number as parameter. Have anybody tried that? I use programs like VoipStunt, but don't know how to start and proceed with given number.
Thanx!
Ante
|
|
|
|
|
RahulRKulkarni wrote: Where would i get information of assembly, webconfig, machineconfig files of .Net
You'll find all that information on MSDN[^]
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
My: Website | Blog
|
|
|
|
|
hi all,
how to disable sorting when one clicks on a columnheader ?
(i programmatically sort according to my wishes. and dont want it to be changed in runtime)
|
|
|
|
|
Are u using BoundFields or Auto-Genereted Fields???
|
|
|
|
|
Message Closed
modified 27-Apr-15 11:12am.
|
|
|
|
|
In property of GridView1 u have AllowSorting property set it to false.
|
|
|
|