String to Integer Smalltalk

北战南征 提交于 2019-12-21 08:01:07

问题


Pretty simple question I need to get an integer from the user and I only know how to get a string from them. So if there is a way to get an integer from the user or to convert the string to an integer please let me know.


回答1:


Found it:

'12345' asNumber.



回答2:


If you are using Squeak or Pharo, learn to use the "Message Finder".

Left click on the background, click Tools > Message Finder. Click on the top left pane. Type:

'12345'. 12345.

Hit Control-S and you have your answer. Specifically, you have three answers: asInteger, asNumber and initialIntegerOrNil.




回答3:


Occasionally you'll want to handle numbers in different bases.

st> s := '3039'.
'3039'
st> Number readFrom: (ReadStream on: s) radix: 16.
12345



回答4:


This page seems to have some conversion examples. Search for Conversion:.

UPDATE

Try using asNumber



来源:https://stackoverflow.com/questions/2226029/string-to-integer-smalltalk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!