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

Looking for volunteers to join your project? Need help with a script but can't afford to pay? Want to offer your services as a volunteer to build up your portfolio? This is the place for you...

Moderator: General Moderators

Post Reply
jhilgert00
Forum Newbie
Posts: 4
Joined: Fri May 05, 2006 6:30 pm

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

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

sscanf() is probably your easiest way of doing this.
jhilgert00
Forum Newbie
Posts: 4
Joined: Fri May 05, 2006 6:30 pm

Post by jhilgert00 »

I dont even now what sscanf() is, I'm looking for someone to volunteer to do this for me (please)
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

How can you claim it's quick and easy if you don't know how it's done yourself??? :?
User avatar
cj5
Forum Commoner
Posts: 60
Joined: Tue Jan 17, 2006 3:38 pm
Location: Long Island, NY, USA

Post by cj5 »

Volunteer?! LMFAO!!!!
User avatar
ambivalent
Forum Contributor
Posts: 173
Joined: Thu Apr 14, 2005 8:58 pm
Location: Toronto, ON

Post 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);
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

cj5 wrote:Volunteer?! LMFAO!!!!
It is the volunteer work forum ;)
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply