Solved

Type Conversion, CString to longbinaray, CString to datetime

Posted on 1997-11-02
2
588 Views
Last Modified: 2013-11-20
hello,
   i'd like to know how can i convert CString to longbinary... and also CString to datetime... thanks, :) mallow
0
Comment
Question by:mallow
2 Comments
 
LVL 5

Accepted Solution

by:
dirtdart earned 20 total points
ID: 1309168
By longbinary I am assuming you mean long.  That is pretty easy.

int len;
CString Num;
long ConvertedNum;
int ct;
char temp;

len = Num.GetLength();

for(ct = 0; ct < len; ++ct)
{
    temp = Num.GetAt(ct);
    ConvertedNum = (long)(temp + 48);
    ConvertedNum *=10;
}


CString to DateTime would go something like this:

int Month;
int Year;
int Day;
int pt;
CString temp;

CString OldDate;
COleDateTime NewDate;

pt = OldDate.Find("/");
temp = OldDate.Left(pt);

//At this point use to code above for converting a CString to a long, just substitiue int for long and set Month equal to the resulting value.  Trim off the value of temp from OldDate and perform this operation twice more to get the Day and Year.  Then call COleDateTime.SetTime(M, D, Y, H, M, S);


0
 

Expert Comment

by:mmachie
ID: 1309169
to conver a cstring to a long value try:
CString num_to_convert;
long converted_num = atol( num_to_convert);

to convert the cstring to a COleDateTime you must parse out the the year, month, and day.  try using the CString::Mid() function.  convert the parsed value using atoi() function then call COleDateTime::SetDate() with the converted values.

hope this helps.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Rewrite URL With Encoded Characters 6 75
Looking for a specific application/software 2 104
How to convert MFC::CString to UTF8 wchar_t* 10 141
SQUD PROXY SERVER, UNIX, SLL/HTTPS 5 73
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now