Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Date Format in String Builder
Message
From
04/06/2014 01:33:13
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01601157
Message ID:
01601245
Views:
26
This message has been marked as a message which has helped to the initial question of the thread.
>>>
>>>sbResult.AppendFormat("{0,20}", row.Field<DateTime?>("date_time").ToString("G"));
>>>
>>>But how to get rid of last AM/PM (BTW, not sure why VFP is removing it as the time will be ambiguous). Same thing of getting rid of last 3 chars?
>>
>>Think if you change the format G and specify 24 hour format, it should not be a problem
>>
>>Console.WriteLine("{0,20:MM/dd/yyyy HH:mm:ss}", DateTime.Now);
>>
>>http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx
>
>I don't understand where is my problem now. Why do I have extra spaces in the beginning I don't have in VFP:
>
>
><ERR>0</ERR><STATUSCODE>0</STATUSCODE><MSG># of Scans: 3
>4/7/2009 5:42:03     1/         TICKET     ADMIN      Valid
>4/7/2009 5:41:35     1/         TICKET     ADMIN      Invalid
>4/7/2009 5:41:29     1/         TICKET     ADMIN      Invalid
></MSG>
><ERR>0</ERR><STATUSCODE>0</STATUSCODE><MSG># of Scans: 3
>   4/7/2009 17:42:03         1/ TICKET     ADMIN      Valid
>   4/7/2009 17:41:35         1/ TICKET     ADMIN      Invalid
>   4/7/2009 17:41:29         1/ TICKET     ADMIN      Invalid
></MSG>
>
>Top is VFP and bottom is C#.
>
>VFP code:
>
> lvRetVal=lvRetVal+'# of Scans: '+transform(reccount())+chr(13)+chr(10)
>                  scan
>                     lvRetVal=lvRetVal+;
>                        padr(substr(transform(date_time),1,len(transform(date_time))-3),20)+' '+;
>                        padr(location2,10)+' '+padr(location,10)+' '+padr(person,10)+' '+;
>                        iif(activ_type=110,'Valid', iif(activ_type=111,'Invalid', 'Valid (rescan)'))+chr(13)+chr(10)
>
>and this is my C# code:
>
>
>sbResult.AppendFormat("{0,20:M/d/yyyy H:mm:ss} {1,10} {2,10} {3,10} {4}\r\n", 
>                        row.Field<DateTime?>("date_time"), row.Field<String>("location2"),
>                        row.Field<String>("location"), row.Field<String>("person"), validStatus);
>
>Do you see why I have spaces in the beginning of the string and why 1/ is not at the same place?
>
>Thanks again.


I see you got your answer by now
		internal static void Go()
		{
			string vfpOutput = @"   4/7/2009 17:42:03         1/ TICKET     ADMIN      Valid";

			DateTime dt = new DateTime(2009, 04, 07, 17, 42, 03);
			string loc2 = "1/";

			StringBuilder sb = new StringBuilder();
			sb.AppendFormat("{0,20:M/d/yyyy H:mm:ss} {1,10}\r\n", 
								dt, loc2
				);

			Console.WriteLine("{0}", vfpOutput);
			Console.WriteLine("{0}", sb.ToString());

			Console.WriteLine("{0,-20:M/d/yyyy H:mm:ss} {1,10}\r\n", 
								dt, loc2
				);

		}
Gives
   4/7/2009 17:42:03         1/ TICKET     ADMIN      Valid
   4/7/2009 17:42:03         1/

4/7/2009 17:42:03            1/
The 1/ is exaclty at the same position ( lines 1 and 2, I copied your vfp output)

Also, take a look at the 3rd line

-20 is like the padR()
where 20 is padL()
Gregory
Previous
Reply
Map
View

Click here to load this message in the networking platform