Code : Tout sélectionner
;MLD le 10/9/2022
;Dans un texte supprimer les éventuels doubles espaces
a$ = "Un nombre flottant est stocké de telle manière que la 'virgule flotte' autour de la partie réelle. De la sorte, "
b$ = "il est possible d'avoir des nombres dont la valeur peut être aussi bien grande que petite. Toutefois vous ne pouvez pas stocker"
c$ =" de grands nombres avec une précision aussi élevée que des petits nombres."
L$ = a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$
L$ = L$ + a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$
L$ = L$ + a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$
L$ = L$ + a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$
L$ = L$ + a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$
L$ = L$ + a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$
L$ = L$ + a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$
L$ = L$ + a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$
L$ = L$ + a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$
L$ = L$ + a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$
L$ = L$ + a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$
L$ = L$ + a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$+a$ + b$ + c$
Procedure.s SS(L$)
max = Len(L$)
For x =1 To max
If Asc(Mid(L$,x,1)) = 32
If Asc(Mid(L$,x+1,1)) = 32
x=x+1
EndIf
EndIf
LL$ = LL$ + Mid(L$,x,1)
Next
ProcedureReturn LL$
EndProcedure
; Micoute
Procedure.s SupprimerEspaces(Chaine.s, separateur.s) ; - supprime les espaces superflus
Protected Caractere.a = 0
Protected Remplissage.a = 0
Protected Sortie.s, i.i
For i = 1 To Len(Chaine)
Caractere = Asc(Mid(Chaine,i,1))
If Caractere <> 32
Remplissage = 1
Sortie + Chr(Caractere)
EndIf
If Caractere = 32 And Remplissage = 1
Remplissage = 0
Sortie + separateur
EndIf
Next
ProcedureReturn Sortie
EndProcedure
; Case
Procedure.s SS2(L$)
max = Len(L$)
For x =1 To max
If Asc(Mid(L$,x,1)) = 32
While Asc(Mid(L$,x+1,1)) = 32 ; ma modification: tant qu'il y a un espace a la position x
x=x+1 ; x+1
Wend ; permet de 'sauter plusieurs espace a la suite car dans ton exemple seul 1 espace est teste.
EndIf
LL$ = LL$ + Mid(L$,x,1)
Next
ProcedureReturn LL$
EndProcedure
; Ar-S
Structure plop
name.s
pos.i
lon.i
EndStructure
Global NewList cible.plop()
Procedure.s ars(l$)
String$ = L$
p$ = "[ ]{2,}" ; 2 espaces ou plus
t0=ElapsedMilliseconds()
CreateRegularExpression(0,p$)
If ExamineRegularExpression(0, string$)
While NextRegularExpressionMatch(0)
AddElement(cible())
cible()\name = RegularExpressionMatchString(0)
cible()\pos = RegularExpressionMatchPosition(0)
cible()\lon = RegularExpressionMatchLength(0)
count+1
Wend
EndIf
ForEach cible()
String$ = ReplaceString(String$,cible()\name,Chr(32),#PB_String_NoCase,0)
Next
ProcedureReturn String$
EndProcedure
; Marc56
Procedure.s marc56(l$)
A$ = L$
If CreateRegularExpression(0, "\h{2,}")
ReplaceRegularExpression(0, A$, " ")
Else
RegularExpressionError()
EndIf
ProcedureReturn a$
EndProcedure
;GallyHC
Procedure.s GallyHC(l$)
text.s = L$
text = Trim(text)
While CountString(text, " ") > 0
text = ReplaceString(text, " ", " ")
Wend
ProcedureReturn text
EndProcedure
Procedure.s mana(L$)
l2$=l$
t=@l$
t2=@l2$
max = Len(L$)
x1 = 0
For x =0 To max+2
If PeekL( t + x<<1) <> $200020
PokeA((t2+x1), PeekL(t+x<<1))
x1=x1+2
EndIf
Next
PokeA((t2+x1), $2e)
ProcedureReturn l2$
EndProcedure
Procedure draw(y,t1$,t2$,t3$,t4$)
StartDrawing(WindowOutput(0))
DrawText(5,y+00,t1$)
DrawText(5,y+20,t2$)
DrawText(5,y+40,"long = "+t3$)
DrawText(5,y+60,"temps = "+t4$)
StopDrawing()
EndProcedure
tx = 1024
ty = 800
If OpenWindow(0, 0, 0, tx, ty, "Exemple...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
StartDrawing(WindowOutput(0))
Box(0,0,tx,ty,0)
DrawText(5,0,"default")
DrawText(5,20,"long = "+Len(l$))
DrawText(5,40,l$)
StopDrawing()
y = 80
t.f=ElapsedMilliseconds()
LL$ = SS(L$)
t.f=ElapsedMilliseconds() - t
lg=Len(ll$)
draw(y,"ss",ll$,Str(lg),Str(t))
y = y + 100
t.f=ElapsedMilliseconds()
LL$ = SupprimerEspaces(L$," ")
t.f=ElapsedMilliseconds() - t
lg=Len(ll$)
draw(y,"Micoute",ll$,Str(lg),Str(t))
y = y + 100
t.f=ElapsedMilliseconds()
LL$ = ss2(L$)
t.f=ElapsedMilliseconds() - t
lg=Len(ll$)
draw(y,"ss2",ll$,Str(lg),Str(t))
y = y + 100
t.f=ElapsedMilliseconds()
LL$ = ars(L$)
t.f=ElapsedMilliseconds() - t
lg=Len(ll$)
draw(y,"ars",ll$,Str(lg),Str(t))
y = y + 100
t.f=ElapsedMilliseconds()
LL$ = marc56(L$)
t.f=ElapsedMilliseconds() - t
lg=Len(ll$)
draw(y,"marc56",ll$,Str(lg),Str(t))
y = y + 100
t.f=ElapsedMilliseconds()
LL$ = GallyHC(L$)
t.f=ElapsedMilliseconds() - t
lg=Len(ll$)
draw(y,"GallyHC",ll$,Str(lg),Str(t))
y = y + 100
t.f=ElapsedMilliseconds()
LL$ = mana(L$)
t.f=ElapsedMilliseconds() - t
lg=Len(ll$)
draw(y,"mana",ll$,Str(lg),Str(t))
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndIf