Home » U++ Library support » U++ Core » int <-> String conversions
int <-> String conversions [message #622] |
Sun, 22 January 2006 14:41 |
hojtsy
Messages: 241 Registered: January 2006 Location: Budapest, Hungary
|
Experienced Member |
|
|
I created a small dummy application with a StaticText and a Button. The Button is supposed to increment the int value displayed in the StaticText.
MyApp::MyApp()
{
CtrlLayout(*this, "Window title");
plus <<= THISBACK(onPlus);
text.SetText("0");
Zoomable().Sizeable();
}
void MyApp::onPlus()
{
int val = StdConvertInt().Scan(text.GetText());
text.SetText(StdConvertInt().Format(val + 1).ToString());
}
Is there a more simple way to do what onPlus does? It seems ugly.
[Updated on: Sun, 22 January 2006 14:41] Report message to a moderator
|
|
|
|
|
Re: int <-> String conversions [message #647 is a reply to message #622] |
Mon, 23 January 2006 16:28 |
|
mirek
Messages: 13980 Registered: November 2005
|
Ultimate Member |
|
|
int->String:
AsString(x)
BTW, AsString is the "standard" function, it is implemented for many types. Moreover, templated
operator<<(String&, T)
and
operator<<(Stream&, T)
are implemented to use AsString, so in most cases, when putting things together, you do not need to care and just put any type on the right side of "<<":
String r; // or e.g. FileOut r;
int i;
Date d;
r << "The number is: " << i << " and the date is: " << d;
String->int:
Well, you can use c library atoi for simple cases. If you are about to have Null option for the empty string, you can use StrIntValue function.
However, in most cases, this is the part of wider text parsing code and that domain is completely ruled by CParser - simple, but extremely useful lexical parser.
|
|
|
Goto Forum:
Current Time: Thu May 16 19:01:25 CEST 2024
Total time taken to generate the page: 0.02601 seconds
|