News:

Function Finder  Find all the functions within source code files

Main Menu

Playing inside strings

Started by reno, December 23, 2008, 08:24:36 AM

Previous topic - Next topic

reno

Hi,

Here are 3 functions to play INSIDE strings.

I work a lot with strings, and PBFX hasn't got all I need build-in ;)

It can help you : insert, change and delete.



; PROJECT : Project3
; AUTHOR  : reno
; CREATED : 23/12/2008
; EDITED  : 23/12/2008
; ---------------------------------------------------------------------

;force les declarations des variables
Explicit 1

;variable
global texte$="PLAY BASIC";normal

;texte
print texte$

;1-3
texte$=iCHAINEinserer(texte$,"& ",6);insert
print texte$

;2-3
texte$=iCHAINEremplacer(texte$,"MORE",1);change
print texte$

;3-3
texte$=iCHAINEsupprimer(texte$,6,3);delete
print texte$


;basculement
sync
waitkey
end




Function iCHAINEinserer(p_chaine1$,p_chaine2$,p_point)

;::::::::::::::::
;inserer une chaine dans une chaine

Local f_longueur1=Len(p_chaine1$)
Local f_longueur2=Len(p_chaine2$)

Local f_temp1$="";-
Local f_temp2$="";-

;**
;**

;si le point de lecture est plus petit ou plus grand que la chaine
If (p_point<1 Or p_point>f_longueur1) Then p_point=1

;mise a jour
f_temp1$=Mid$(p_chaine1$,1,(p_point-1))
f_temp2$=Mid$(p_chaine1$,p_point,(f_longueur1-(p_point-1)))

f_temp1$=(f_temp1$+p_chaine2$+f_temp2$)

EndFunction f_temp1$




Function iCHAINEremplacer(p_chaine1$,p_chaine2$,p_point)

;::::::::::::::::
;remplacer une chaine dans une chaine

Local f_longueur1=Len(p_chaine1$)
Local f_longueur2=Len(p_chaine2$)

Local f_temp1$="";-
Local f_temp2$="";-
Local f_temp3$="";-

;**
;**

;si la chaine est vide
If p_chaine1$="" Then Exitfunction

;si le point de lecture est plus petit ou plus grand que la chaine
If (p_point<1 Or p_point>f_longueur1) Then p_point=1

;mise a jour
f_temp1$=Mid$(p_chaine1$,1,(p_point-1))
f_temp2$=p_chaine2$
f_temp3$=Mid$(p_chaine1$,(p_point+f_longueur2),(f_longueur1-(p_point+(f_longueur2-1))))

f_temp1$=(f_temp1$+f_temp2$+f_temp3$)

EndFunction f_temp1$




Function iCHAINEsupprimer(p_chaine1$,p_longueur,p_point)

;::::::::::::::::
;supprimer une chaine dans une chaine

Local f_longueur1=Len(p_chaine1$)

Local f_temp1$="";-
Local f_temp2$="";-

;**
;**

;si la chaine est vide
If p_chaine1$="" Then Exitfunction

;si le point de lecture est plus petit ou plus grand que la chaine
If (p_point<1 Or p_point>f_longueur1) Then p_point=1

;mise a jour
f_temp1$=Mid$(p_chaine1$,1,(p_point-1))
f_temp2$=Mid$(p_chaine1$,(p_point+p_longueur),(f_longueur1-(p_point+(p_longueur-1))))

f_temp1$=(f_temp1$+f_temp2$)

EndFunction f_temp1$


More games ? Go to my website :)
http://www.thereeteam.com/