Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 1,213 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Help with parsing block of text from file #259611
04/06/09 21:50
04/06/09 21:50
Joined: Jul 2005
Posts: 192
Orange County
S
silencer Offline OP
Member
silencer  Offline OP
Member
S

Joined: Jul 2005
Posts: 192
Orange County
So I have a text file I need to read from. In the text file the text is formatted in the following manner.

Code:
[someString1,someString2,someString3]
[someStrhing4,seomStrhing5,someStrhing6]


I need to write a loop that will recognize the "[" opening bracket, bypass it, and then continue reading the strings (using the "," as a delimit character) until the next "[" opening bracket is hit, at which point the loop should terminate.

Additionally I have an int variable counting the amount of "[" opening brackets hit while parsing. I will use this counter to switch between different blocks of strings when needed.

So far I have the following:
Code:
	fhandle = file_open_read (filename); // Opening file
	
	while(eof != -1){
		eof = file_str_read(fhandle, test_str);
		str_cpy( (dialog_file.pstring)[count], test_str); //Pushing lines into array
	   count += 1;
	}


How do I utilize an extra delimiter character to count the "[" opening brackets?


AMD 64 x2 4400+ 2048mb DDR3200 NVidia 6800GS 256mb Soundblaster Audigy 2 A7 Commercial 7.07
Re: Help with parsing block of text from file [Re: silencer] #259651
04/07/09 03:55
04/07/09 03:55
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Try this (tested) code to see of its what you are after.
Code:
	var fhandle = file_open_read("diag.txt");
	var groups=0;
	while(eof != -1)
	{
		eof = file_str_read(fhandle, test_str);
		if(eof>0) 
		{
			if(str_to_asc(test_str)==str_to_asc(_str("[")))								// <<- can be simplified to if((test_str.chars)[0]==91)
			{	
				groups += 1;	//increment group counter
				str_clip(test_str,1);	//remove leading "["
			}
			if((test_str.chars)[str_len(test_str)-1]==str_to_asc(_str("]")))		// <<- can be simplified to if((test_str.chars)[str_len(test_str)-1]==93)
			{	str_trunc(test_str,1);	/*remove any "]"*/	}		
			str_cpy( (dialog_file.pstring)[count], test_str);		//Push lines into array
			count += 1;		//increment total-strings count
		}
	}






"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Help with parsing block of text from file [Re: EvilSOB] #259782
04/07/09 16:57
04/07/09 16:57
Joined: Jul 2005
Posts: 192
Orange County
S
silencer Offline OP
Member
silencer  Offline OP
Member
S

Joined: Jul 2005
Posts: 192
Orange County
Ah thanks EvilSOB, that seems to be what I'm looking for. I didn't know about the "str_clip" and str_trunc functions.

Just to check, if I wanted to say start pushing the strings from "block 2" in my text file, I'd just need an if-statement around the block where I'm pushing the strings into the array to check if the counter was equal to 2 (or 3 or 4, depending on what block of strings I wanted to put into the array).


AMD 64 x2 4400+ 2048mb DDR3200 NVidia 6800GS 256mb Soundblaster Audigy 2 A7 Commercial 7.07
Re: Help with parsing block of text from file [Re: silencer] #259858
04/08/09 00:46
04/08/09 00:46
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
just around the STR_CPY and the count would DO, but the
loop would keep reading after its gotten what it wants. Not efficient.
Put a break; inside that if too and its better.


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1