home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / pascal / 8638 < prev    next >
Encoding:
Internet Message Format  |  1993-01-28  |  1.6 KB

  1. Path: sparky!uunet!ukma!darwin.sura.net!lhc!adm!news
  2. From: ZCCBJSB@eb0ub012.bitnet (Josep Sau)
  3. Newsgroups: comp.lang.pascal
  4. Subject: integer/string generic
  5. Message-ID: <35241@adm.brl.mil>
  6. Date: 27 Jan 93 11:03:06 GMT
  7. Sender: news@adm.brl.mil
  8. Lines: 47
  9.  
  10.  
  11.  
  12. >from: "r. patel" <rpatel@massey.ac.nz>
  13. >subject: string and integer conversion (mac and pc) - help
  14. >date: 25 jan 93 20:25:22 gmt
  15. >to:       info-pascal@brl.mil
  16. >
  17. >anyway i've got a pascal prog. on the mac which uses the sane library
  18. >functions int2str and str2int (ie converts a string to integer and
  19. >viceversa).
  20.  
  21. >from: patrick pollet <ppollet@cismibm.univ-lyon1.fr>
  22. >subject: re: string and integer conversion (mac and pc) - help
  23. >date: 26 jan 93 08:25:59 gmt
  24. >to:       info-pascal@brl.mil
  25. >
  26. >  int2str should be changed to str()
  27. >  str2int should be changed to val()
  28. >  Caution: The parameters are differents and Str() and val() are
  29. > PROCEDURES whereas int2str() and str2int() are functions.
  30.  
  31.  I normally use these sub-programs and avoid raw STR or VAL
  32.  in code. Perhaps you may profit from them:
  33.  
  34.  FUNCTION IntStr (lng :LONGINT) :STRING;
  35.  (* LONGINT -> STRING,
  36.  minimal integer representation. *)
  37.  VAR
  38.    s :STRING;
  39.    i :INTEGER;
  40.  BEGIN
  41.    SYSTEM.STR(lng:0,s);
  42.    IntStr := s;
  43.  END;
  44.  
  45.  FUNCTION IntVal (s :STRING; VAR lng :LONGINT) :BOOLEAN;
  46.  (* STRING -> LONGINT,
  47.  returns TRUE if integer numeric conversion succeed *)
  48.  VAR i :INTEGER;
  49.  BEGIN
  50.    SYSTEM.VAL(s,lng,i);
  51.    IntVal := i = 0;
  52.  END;
  53.  
  54. -- Josep Sau: zccbjsb@eb0ub012.bitnet
  55. -- Library application programmer, Universitat de Barcelona.
  56. -- Enjoying TP/DOS. Using PLI/VM, REXX/VM. Suffering NATURAL/ADABAS.
  57.