Pascal 中的字符串到整数转换,怎么做? [英] string to integer conversion in Pascal, How to do it?

查看:73
本文介绍了Pascal 中的字符串到整数转换,怎么做?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将字符串中打印的数字转换为整数?

How to convert a number printed in a string into integer?

谢谢.

推荐答案

是程序 Val:

procedure Val(S; var V; var Code: Integer);

此过程对十进制数和实数进行运算.

This procedure operate on decimal and real numbers.

参数:

  • S 字符序列;为了正确转换,它必须包含+"、-"、,"、."、0"..9".
  • V 转换的结果.如果结果将是一个整数,那么 S 不能包含‘,’,‘.’.
  • C 从 S 返回字符的位置,中断转换.

用例:

Var Value :Integer;

Val('1234', Value, Code);  // Value = 1234, Code = 0
Val('1.234', Value, Code); // Value = 0, Code = 2
Val('abcd', Value, Code);  // Value = 0, Code = 1

这篇关于Pascal 中的字符串到整数转换,怎么做?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆