Solved

Easy Format Question

Posted on 2004-03-21
4
175 Views
Last Modified: 2013-11-20
Hi

Using CString::Format how do I format 1234 to be 1,234
0
Comment
Question by:Dj_Fx8
  • 2
4 Comments
 
LVL 5

Accepted Solution

by:
info_expert earned 125 total points
ID: 10644630
There is no specific automatic method for this purpose in CString, but u can use your brain.
the len method of CString  returns the length of CString. you will do:

int groups=s1.len() /3;
CString s2;

now as you know the length of string

for(int c=len; c>3; c-=3)
{
//take the substring from s1 and put in s2 and then put the comma in s2.
//the length of s2 will be = s1.len() + groups;
}

Got?

Regards
0
 
LVL 5

Expert Comment

by:info_expert
ID: 10644652
One thing i forgot to tell that you can use the same string and use the 'insert' function to insert the commas in string but you will have to determine the number of groups of strings to be made in source string.
0
 

Author Comment

by:Dj_Fx8
ID: 10644717
Hi

>>>u can use your brain

I was hoping I wouldn't have to do that :-) I have no prob working it out, but just was wondering if there was an easier way.

Many Thanks
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 10647737
Have a look at GetNumberFormat in help.
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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

895 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

16 Experts available now in Live!

Get 1:1 Help Now