i want easy to manager object for project,so i design this code likes this.
did you have any good ideas for this code? tell me. laugh
Code:
function getstr(STRING* str,var t){
	STRING* sign=",";
	STRING*	temp="";
	STRING* res ="error message";
	var le=1;
	var i=1;
	char* c=str->chars;	
	str_cpy(temp,c);
	if(str_stri(str,sign)==0){
		printf("error,can`t find ths sign string of divide!");
		return res; 
	}
	while(le!=0){
		STRING* s1="";STRING* s2="";
		str_cpy(s1,temp->chars);	
		str_cpy(s2,temp->chars);
		le =  str_stri(s1,sign);
		str_trunc(s1,(str_len(s1)-le+1));
		str_clip(s2,le);
		str_cpy(temp,s2);
		if(i==t){return s1;}
		i+=1;
	}
}
function setstr(STRING* str,STRING* modstr,var t){
	STRING* sign=",";
	STRING*	temp="";
	STRING* res ="";
	var le = 1;
	var i=1;
	char* c=str->chars;
	str_cpy(temp,c);
	while(le!=0){
		STRING* s1="";STRING* s2="";
		str_cpy(s1,temp->chars);	
		str_cpy(s2,temp->chars);
		le =  str_stri(s1,sign);
		str_trunc(s1,(str_len(s1)-le+1));
		str_clip(s2,le);
		str_cpy(temp,s2);
		if(i==t){str_cpy(s1,modstr->chars);}
		str_cat(res,s1);
		str_cat(res,sign);
		i+=1;
	}
	str_trunc(res,1);
	return res;
}
STRING* gtest="";
function main(){
	video_mode = 1;
	fps_max = 24;
	level_load("");

	STRING* gs1 = "12,323,hello,tom,909,io,";
	gtest=getstr(gs1,6);

	STRING* s1 = "ko";
	gtest =	setstr(gs1,s1,2);
}



Last edited by frankjiang; 08/12/10 12:44.

development 3d game is interesting!