Page 1 of 1

Quick and easy, I just don't know how, please help.

Posted: Fri May 05, 2006 6:44 pm
by jhilgert00
I'm not even sure if this is the right place to post this, but here goes;

I have a text file containing a list of xyz coordinates in the following format: (approximately 5,000 lines/coordinates)

Code: Select all

v -326.325 229.484 -29.1376
v -325.147 232.794 -9.30042
v -323.186 235.466 10.3415
v -320.466 237.567 29.3886
v -316.924 239.187 48.4642
v -312.642 240.25 67.3441
v -307.034 240.916 87.689
v -299.938 240.916 109.528
I need to convert all the decimals to integers, put a comma between the integers, and wrap
each line with parethesesfollowed by a comma
so the list will look like this:

Code: Select all

(-326,229,-29),
(-325,232,-9),
(-323.186,235,10),
(-320,237,29),
(-316,239,48),
(-312,240,67),
(-307,240,87),
(-299,240,109),

If you are a database guru and you can do this quickly, it will save me endless hours of work. I'm a graphic designer
so i have no idea how to manipulate text files at all, any help whatsoever will be greatly appreciated.

thanks in advance for any assistance

Posted: Fri May 05, 2006 7:08 pm
by feyd
sscanf() is probably your easiest way of doing this.

Posted: Fri May 05, 2006 7:26 pm
by jhilgert00
I dont even now what sscanf() is, I'm looking for someone to volunteer to do this for me (please)

Posted: Fri May 05, 2006 10:10 pm
by alex.barylski
How can you claim it's quick and easy if you don't know how it's done yourself??? :?

Posted: Fri May 05, 2006 10:40 pm
by cj5
Volunteer?! LMFAO!!!!

Posted: Fri May 05, 2006 11:14 pm
by ambivalent
Only because I had nothing better to do. It's quick and dirty but should get the job done. It seems to work as advertised on the data format specified in the first post.

Code: Select all

$file = "list.txt";  //input file

$inputFile = file($file);

$fileHandle = fopen("newlist.txt", "w+");  //output file

foreach($inputFile as $line)

{

	$line = substr($line, 2);
	$lines = explode(" ", $line);
	
	$num1 = round($lines[0], 0);
	$num2 = round($lines[1], 0);
	$num3 = round($lines[2], 0);
		
	$lineWrite = "(";
	$lineWrite .= $num1.",";
	$lineWrite .= $num2.",";
	$lineWrite .= $num3."),\r\n";

	
	fwrite($fileHandle, $lineWrite); 

}

fclose($fileHandle);

Posted: Sat May 06, 2006 2:53 am
by s.dot
cj5 wrote:Volunteer?! LMFAO!!!!
It is the volunteer work forum ;)