GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 18-Feb-2005, 14:51
toddm123 toddm123 is offline
New Member
 
Join Date: Feb 2005
Posts: 9
toddm123 is on a distinguished road

Custom String Formatting


Hi All,

I'm using c++.net and have a string that represents a date.

"122804"(mmddyy)

Any ideas on using DateTimeFormatInfo to take that value and make it:

"20041228" (yyyymmdd)

or if not possible:

"041228"(yymmdd)

Any help would be great.

Thanks a lot,
Todd
  #2  
Old 18-Feb-2005, 23:20
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,258
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
You'll have to split and recombine it yourself. A simple function would do it.
__________________

Got a cough? Go home tonight and eat a whole box of Ex-Lax. Tomorrow, you'll be afraid to cough.
-- Pearl Williams
  #3  
Old 21-Feb-2005, 09:33
toddm123 toddm123 is offline
New Member
 
Join Date: Feb 2005
Posts: 9
toddm123 is on a distinguished road
Quote:
Originally Posted by WaltP
You'll have to split and recombine it yourself. A simple function would do it.

Cool I figured as much.

Thanks,
Todd
  #4  
Old 02-Mar-2005, 08:32
LuciWiz's Avatar
LuciWiz LuciWiz is offline
Moderator
 
Join Date: Jul 2004
Location: Cluj-Napoca (Romania)
Posts: 961
LuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the rough
Hi, Todd.

I'm sorry I overlooked this thread. I meant to post an answer, but the notification message got lost in the mess called my mail account
From what I understood, you are looking for a solution based on the .NET Framework. However, this was the wrong forum to post your thread. You should have posted in the .NET Forum, and I'm sure you would have gotten a solution earlier. Walt gave you a solution based on what you required by posting here. Simply stating that you use vc.net does not imply that you are using managed code.

Please don't take this the wrong way; I'm simply explaining the answer you got.

In fact, you have the possibility to accomplish what you required by means of the DateTimeFormatInfo class. Actually, you can do it without making use of it at all.

If you would have the date in the DateTime format, I think you agree that this is pretty simple:

CPP / C++ / C Code:
using namespace System;
using namespace System::Globalization;

int _tmain()
{
	CultureInfo * pCIenUS = new CultureInfo(S"en-US", false);
	CultureInfo * pCIjaJP = new CultureInfo(S"ja-JP", false);

	DateTime myDT = DateTime(2004, 12, 28);

	Console::WriteLine(S"en-US: {0}", myDT.ToString(S"F", pCIenUS));
	Console::WriteLine(S"Jap: {0}", myDT.ToString(S"F", pCIjaJP));

	return 0;
}

So, the trick would be to transform your string into that. That's not so difficult either:

CPP / C++ / C Code:
using namespace System;
using namespace System::Globalization;

int _tmain()
{

	CultureInfo * pCIenUS = new CultureInfo(S"en-US", false);
	CultureInfo * pCIjaJP = new CultureInfo(S"ja-JP", false);

	String * date = new String("12/28/04");
	//Convert the date in the string 
	//Tell "it" the initial format is the US version
	DateTime myDT = Convert::ToDateTime(date, pCIenUS);

	//let's see what it looks like in the original
	Console::WriteLine(S"en-US: {0}", myDT.ToString(S"F", pCIenUS));
	//and now, the Japanese version
	Console::WriteLine(S"ja-JP: {0}", myDT.ToString(S"F", pCIjaJP));

	// I'm not sure why the output is so "ugly"
	//the following works well
	CultureInfo* pCIdeDE = new CultureInfo(S"de-DE", false);
	Console::WriteLine(S"de-DE: {0}", myDT.ToString(S"F", pCIdeDE));

	//If you didn't figure it out, it's  German :)
	return 0;
}

In case this was not what you required and my understanding of your post was flawed, please correct me. Also, I'm sorry if my answer arrived to late for you to make use of it.
In case you confirm that you were looking for a solution that makes use of the .NET Framework, I will move this thread to the appropriate forum.

Kind regards,
Lucian
__________________
Please read these Guidelines before posting on the forum

"A person who never made a mistake never tried anything new."
Einstein
  #5  
Old 03-Mar-2005, 09:32
toddm123 toddm123 is offline
New Member
 
Join Date: Feb 2005
Posts: 9
toddm123 is on a distinguished road
Lucian,

I really appreciate your response. I looked at that class and ended up deciding that a simple string format would work in a lot less code. If the string dates I was getting were valid date formats then I might be tempted to go the route you mention but they're not. I'd have to do string formatting on my inputs JUST to begin to use the code you mention.

Again, I appreciate your response a lot and you've cleared up some questions I still had regarding the CultureInfo class.

Thanks again,
Todd
 
 

Recent GIDBlogUS Elections and the ?Voter?s Responsibility? by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Read a .html file, check that file for links salemite C Programming Language 10 17-Jan-2008 08:56
Re: Conversion: Binary, Decimal, Hexadecimal WaltP C Programming Language 1 10-May-2006 07:49
C++ string from file small_ticket C++ Forum 3 05-Jan-2005 08:29
storing a token pointer as a string CoreLEx C Programming Language 1 07-Oct-2003 12:33

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 05:04.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.