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++ TheIDE » U++ TheIDE: Compiling, Linking, Debugging of your packages » String to int
String to int [message #27588] Sat, 24 July 2010 23:00 Go to next message
morley is currently offline  morley
Messages: 10
Registered: January 2007
Promising Member
How to I convert a upp String, assigned to say "122", to an int?

I saw a function to get individual characters from a string so I suppose I could concatenate these into a char array and use a_toi or something, but I presume there is something simpler.

Thanks!
Re: String to int [message #27589 is a reply to message #27588] Sun, 25 July 2010 01:08 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

morley wrote on Sat, 24 July 2010 23:00

How to I convert a upp String, assigned to say "122", to an int?

I saw a function to get individual characters from a string so I suppose I could concatenate these into a char array and use a_toi or something, but I presume there is something simpler.

Thanks!

Hi morley,

Yes, there is something simpler. For string<->integer there are StrInt() and IntStr(), for double DblStr and StrDbl plus few more for other types.

Honza
Re: String to int [message #27590 is a reply to message #27589] Sun, 25 July 2010 07:54 Go to previous messageGo to next message
morley is currently offline  morley
Messages: 10
Registered: January 2007
Promising Member
Thanks for the help! It is interesting that the StrInt(char *) works with both c-character strings and the Upp String type.

Re: String to int [message #27597 is a reply to message #27590] Sun, 25 July 2010 12:20 Go to previous message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

morley wrote on Sun, 25 July 2010 07:54

Thanks for the help! It is interesting that the StrInt(char *) works with both c-character strings and the Upp String type.

You're welcome Smile

The magic converting char* to String is one of the C++ features that make programmers life a bit easier. If there is a conversion operator defined, it is used automatically. For the String->const char * there is "operator const char *() const" defined in String (actually in String0, but that is implementation detail). For the other way, const char*->String, C++ just uses the constructor String(const char *s) to convert the type.

Honza
Previous Topic: Version of NASM
Next Topic: TheIDE crash when compile with "All Shared" option
Goto Forum:
  


Current Time: Tue Apr 16 06:04:04 CEST 2024

Total time taken to generate the page: 0.01648 seconds