convert strings in a file to integer
am 09.01.2005 18:51:35 von info
I got a file with a lot of numbers that are strings. I'd like to read all
this numbers and convert them to numbers for futher compareation. How can I
convert all this numbers to integer?
regards
frengky
--
Organisation nr: 983063349
Frengky, Olsokveien 65,1727 Sarpsborg, Norway
Tel: +47 92611725
Fax: +47 69152017
Email: oystein.western@frengky.no
Web: www.frengky.no
Re: convert strings in a file to integer
am 12.01.2005 13:31:56 von Erwin Moller
�stein Western wrote:
> I got a file with a lot of numbers that are strings. I'd like to read all
> this numbers and convert them to numbers for futher compareation. How can
> I convert all this numbers to integer?
>
> regards
> frengky
>
Hi
Easiest way: Use some sciptinglanguage.
PHP or Perl or something like that.
(I prefer PHP)
Just open the file, get the numbers out, and create a whole bunch of
INSERTS.
Then execute.
In PHP, use the file() command to retrieve all the lines in an array.
for example:
(Some fantasycode)
$myLines = file("/home/stein/somenumbers.txt");
$SQL = "";
for($i=0;$i
$myNum = (int)$myLines($i);
SQL .= "INSERT INTO tblnumbers (anumber) VALUES (".$myNum.");\n";
}
pg_execute($SQL);
or
echo replace("\n","
",$SQL);
Something like that.
Good luck!
Regards,
Erwin Moller