C++/CLI string formatting
-
int MyInt;
String^ MyString = MyInt.ToString();Guys, I need some help on C++/CLI please. Given an Int ("MyInt") how can I generate a string called "MyString" which is made up of only the first let's say 5 digits of the Int? I guess there must be a simple attribute that I can specify in the line above but I cannot find the right sintax. Any help would be appreciated. Many thanks.
-
int MyInt;
String^ MyString = MyInt.ToString();Guys, I need some help on C++/CLI please. Given an Int ("MyInt") how can I generate a string called "MyString" which is made up of only the first let's say 5 digits of the Int? I guess there must be a simple attribute that I can specify in the line above but I cannot find the right sintax. Any help would be appreciated. Many thanks.
Hi, no there is no optional parameter that lets you specify that you only are interested in the N leftmost or N rightmost digits; ToString() will give all of them, you can throw away the part you do not want using string::SubString(). Not sure it makes much sense to do so. :)
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
-
Hi, no there is no optional parameter that lets you specify that you only are interested in the N leftmost or N rightmost digits; ToString() will give all of them, you can throw away the part you do not want using string::SubString(). Not sure it makes much sense to do so. :)
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
One could go totally overkill and implement an IFormatProvider/ICustomFormatter that automatically trims the string (using Convert.ToString(Intxx, IFormatProvider)). :laugh:
Mark Salsbery Microsoft MVP - Visual C++ :java: