How to search and replace with in 2d array in android -
i have sqlite db 4 columns. i.e. id , rule body, cons , bool. can insert data , retrieve using cursor , store in 2d array. example row can like
id rule body cons bool 1 jogging(?x) athelete(?x) 0 2 athelete(?x) runsfast(?x) 0 3 athelete(?x),runsfast(?x) champion(?x) 0
same structure of array without columns heading. want user has give input in following format
jogging(alan)
it has replace ?x in 2darray , enter alan in ?x place.
1 jogging(alan) athelete(alan) 0 2 athelete(alan) runsfast(alan) 0 3 athelete(alan),runsfast(alan) champion(alan) 0
if jogging(alan) found copy cons of jogging(alan) newarray[].
newarray[athelete(alan)]
newarray[] carry athlete(alan). newarray[] has been updated search again athlete(alan) if found save runsfast(alan) newarray[]. again updated , have athelete(alan),runsfast(alan) in newarray[].
newarray[athelete(alan),runfast(alan)]
now search athelete(alan),runsfast(alan) , add champion(alan) newarray[] repeat again , time no match found quit.
newarray[athelete(alan),runfast(alan),runfast(alan)]
any ideas please
one way use split using character in ur case ( split joggin(?x) jogging , ?x) u can strip ) using replace method. jogging(alan) joggin , alan) add them arraylist or storing structure u can use ease. in case of array u can search if
rule[x] matches fact[x] copy fact[x+1] rule[x+1]
so in case find jogging in 1 array equal jogging in other array, copy next item other array replacing ?x.
i guess u r working on rule based horn-clauses thats why u r using format?
Comments
Post a Comment