Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » int <-> String conversions
int <-> String conversions [message #622] Sun, 22 January 2006 14:41 Go to next message
hojtsy is currently offline  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 #623 is a reply to message #622] Sun, 22 January 2006 16:13 Go to previous messageGo to next message
zsolt is currently offline  zsolt
Messages: 698
Registered: December 2005
Location: Budapest, Hungary
Contributor
Try using EditInt or EditIntSpin.
Re: int <-> String conversions [message #624 is a reply to message #623] Sun, 22 January 2006 16:17 Go to previous messageGo to next message
hojtsy is currently offline  hojtsy
Messages: 241
Registered: January 2006
Location: Budapest, Hungary
Experienced Member
I know those widgets. This is just a dummy example for int <-> String conversion in u++. Do you know an easier way for that?
Re: int <-> String conversions [message #647 is a reply to message #622] Mon, 23 January 2006 16:28 Go to previous message
mirek is currently offline  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.
Previous Topic: Need help...
Next Topic: regex (assembly) from boost
Goto Forum:
  


Current Time: Thu May 16 19:01:25 CEST 2024

Total time taken to generate the page: 0.02601 seconds