473,320 Members | 1,694 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,320 software developers and data experts.

String format...

i have this structure...

struct tFullTime
{
public int Year;
public int Month;
public int Day;
public int Hour;
public int Min;
public int Sec;
public int Hun;
} tSrcTime;
this is C++ code....

CString sReturn;
sReturn.Format( "%02d:%02d:%02d - %02d/%02d/%02d",
tSrcTime.Hour,
tSrcTime.Min,
tSrcTime.Sec,
tSrcTime.Month,
tSrcTime.Day,
tSrcTime.Year);

how to format strings like this in C#.NET?

Nov 29 '06 #1
3 5947
"karthee" <ka**************@gmail.comwrote in message
news:11**********************@16g2000cwy.googlegro ups.com...
CString sReturn;
sReturn.Format( "%02d:%02d:%02d - %02d/%02d/%02d",
tSrcTime.Hour,
tSrcTime.Min,
tSrcTime.Sec,
tSrcTime.Month,
tSrcTime.Day,
tSrcTime.Year);

how to format strings like this in C#.NET?
I generally don't use this method and just concatenate the string myself but
I believe you can do string.Format(....) in pretty much the same way. It is
a static function of the string class.
>

Nov 29 '06 #2
Hi,

Considering you are basically working with a DateTime object, why not
scrap fFullTime and use DateTime instead?
To format your date and time simply do DateTime.ToString("hh:mm:ss -
MM/dd/yy"). You could also use DateTime.ToString() for the default output
(culture specific).

The / in DateTime.ToString also has a special meaning, which may be
culture specific. On my system I had to do @"hh:mm:ss - MM\/dd\/yy" to be
able to display as 11/29/06.


On Wed, 29 Nov 2006 06:23:05 +0100, karthee <ka**************@gmail.com>
wrote:
i have this structure...

struct tFullTime
{
public int Year;
public int Month;
public int Day;
public int Hour;
public int Min;
public int Sec;
public int Hun;
} tSrcTime;
this is C++ code....

CString sReturn;
sReturn.Format( "%02d:%02d:%02d - %02d/%02d/%02d",
tSrcTime.Hour,
tSrcTime.Min,
tSrcTime.Sec,
tSrcTime.Month,
tSrcTime.Day,
tSrcTime.Year);

how to format strings like this in C#.NET?


--
Happy Coding!
Morten Wennevik [C# MVP]
Nov 29 '06 #3

karthee wrote:
i have this structure...

struct tFullTime
{
public int Year;
public int Month;
public int Day;
public int Hour;
public int Min;
public int Sec;
public int Hun;
} tSrcTime;
this is C++ code....

CString sReturn;
sReturn.Format( "%02d:%02d:%02d - %02d/%02d/%02d",
tSrcTime.Hour,
tSrcTime.Min,
tSrcTime.Sec,
tSrcTime.Month,
tSrcTime.Day,
tSrcTime.Year);

how to format strings like this in C#.NET?
string return = String.Format("{0:00}:{1:00}:{2:00} -
{3:00}/{4:00}/{5:00}",
tSrcTime.Hour,
tSrcTime.Min,
tSrcTime.Sec,
tSrcTime.Month,
tSrcTime.Day,
tSrcTime.Year);
Other guys totally lost.

Nov 29 '06 #4

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

Similar topics

2
by: san | last post by:
Hello, all! I have question about String.Format method. There are two variants: public static string Format(string, params object); and public static string Format(IFormatProvider, string, params...
5
by: raffelm | last post by:
I'm struggling to find a way to include long path names in a command line argument string that I have to build at runtime. I need to create a string like -o:"c:\my documents\my file.txt". ...
2
by: Bob | last post by:
I'm having trouble the string.Format() throwing exceptions and I can't figure out what I am doing wrong. Given the following setup code: string str = { "one", "two", "three", "four" }; double...
7
by: Alpha | last post by:
Hi, I'm maintaining C# code and am fairly new with C# programming. I'm looking for codes that's droping the 2nd digit of a nuber printed out and I suspect it's the code below. Can someone tell me...
6
by: Scewbedew | last post by:
Suppose I have the following code: string myFormat = "Line1/nLine 2"; string formattedString = string.Format(myFormat); ....that would produce a 2-line output as expected. But if I load...
8
by: Lucky | last post by:
hi guys! back again with another query. the problem is like this. i want to print a line like this: "---------------------------------------------" the easiest way is to simply assign it to...
4
by: carry | last post by:
Hi everybody, I need simple string formatting like string.Format() does, but just with strings what seems not to work. Can anyone tell me please why this doesn't work and how can it be done? This...
1
by: Remi THOMAS | last post by:
Hi, When you execute this line of code string script = string.Format("foreach (GroupDoc gdoc in {0}.SetGroup(\"{1}\") {\r\n", "p1", "p2"); You get System.FormatException was unhandled...
7
by: Rick | last post by:
With String.Format, if I have an incorrect number of args specified for a format string, compile fails. How can I implement similar design-time functionality for my own string functions?
8
by: Armando Rocha | last post by:
Hi, Hi have a string with 16 chars "25DD68EDEB8D5E11" and i want show it in form like this "25DD-68ED-EB8D-5E11", i try String.Format("{0:####-####-####-####}", mystr), but not work, i think...
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...
0
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...
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: 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: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work

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.