Accueil > > > GESTION CHAÎNES DE CARACTÈRES : "TOKEN"
GESTION CHAÎNES DE CARACTÈRES : "TOKEN"
Information sur la source
Description
Ce sont tout simplement pour ceux qui connaissent mIRC la reproduction des fonctions "token" (qui signifie "marque" je crois) comme $gettok, $numtok, $findtok et d'autres... qui permettent de gérer des chaînes de caractère. Utilisation : - AddTok(chaine As String, add As String, char As String) : Ajoute un token à la fin du texte. addtok("a.b.c","d",".") retourne a.b.c.d addtok("a.b.c.d","c",".") retourne a.b.c.d.c - DelTok(chaine As String, n As Integer, char As String) : Efface le Nième token du texte. deltok("a.b.c.d",3,".") retourne a.b.d - FindTok(chaine As String, ch As String, n As Integer, char As String) : Retourne la position du Nième token correspondant dans le texte. findtok("a.b.c.d","c",1,".") retourne 3 - GetTok(chaine As String, n As Integer, char As String) : Retourne le Nième token du texte. gettok("a.b.c.d.e",3,".") retourne c - InsTok(chaine As String, ins As String, n As Integer, char As String) : Insère le token à la Nième position dans le texte. instok("a.b.d","c",3,".") retourne a.b.c.d - IsTok(chaine As String, ch As String, char As String) : Retourne true si le token existe, sinon false. - NumTok(chaine As String, char As String) : Retourne le nombre de tokens dans le texte. - PutTok(chaine As String, ch As String, n As Integer, char As String) : Réécrit par-dessus le Nième token dans le texte avec un nouveau token. puttok("a.b.c.d","e",2,".") retourne a.e.c.d - RemTok(chaine As String, ch As String, n As Integer, char As String) : Enlève le Nième token correspondant du texte. remtok("a.b.c.d","b",1,".") retourne a.c.d remtok("a.b.c.d","e",1,".") retourne a.b.c.d remtok("a.c.c.d","c",1,".") retourne a.c.d - RepTok(chaine As String, ch As String, nouv As String, nb As Integer, char As String) : Remplace le Nième token correspondant du texte avec un nouveau token. reptok("a.b.c.d","b","e",1,".") retourne a.e.c.d reptok("a.b.c.d","f","e",1,".") retourne a.b.c.d reptok("a.b.a.c","a","e",2,".") retourne a.b.e.c - TrimTok(chaine As String, char As String) : trimtok("..a.....b.c...d....", ".") retourne a.b.c.d
Source
- 'Fonctions "TOKEN" ("marque") : fonctions de gestion de chaînes de caractères codées en VB6 par Tim alias HeXoR (hexor@wanadoo.fr - hexor47@hotmail.com) :)
- 'AddTok(...) ; DelTok(...) ; FindTok(...); GetTok(...) ; InsTok(...) ; IsTok(...) ; NumTok(...) ; PutTok(...) ; RemTok(...) ; RepTok(...) ; TrimTok(...)
- 'Dernière mise à jour le 05/03/2004 à 14h17 GMT+1
- 'Attention il est fortement conseillé d'insérer toutes les fonctions et non pas seulement celle qui vous intéresse car chaque de fonction a besoin des autres fonctions (à part TrimTok(...))
-
-
- Public Function AddTok(chaine As String, add As String, char As String)
- AddTok = TrimTok(chaine, char) & char & add
- End Function
-
- Public Function DelTok(chaine As String, nb As Integer, char As String)
- Dim x As Integer
- Dim result As String
- chaine = TrimTok(chaine, char)
- While x < nb
- result = result & char & GetTok(chaine, x, char)
- x = x + 1
- Wend
- While x < NumTok(chaine, char)
- x = x + 1
- result = result & char & GetTok(chaine, x, char)
- Wend
- DelTok = TrimTok(result, char)
- End Function
-
- Public Function FindTok(chaine As String, ch As String, nb As Integer, char As String)
- Dim y As Integer
- Dim x As Integer
- chaine = TrimTok(chaine, char)
- 'y = 0
- While y < nb
- x = x + 1
- If GetTok(chaine, x, char) = ch And nb = 1 Then FindTok = x
- If GetTok(chaine, x, char) = ch Then y = y + 1
- If y = nb Then FindTok = x
- Wend
- End Function
-
- Public Function GetTok(chaine As String, nb As Integer, char As String)
- Dim x, y, d As Integer
- chaine = TrimTok(chaine, char)
- x = 1
- Do
- y = y + 1
- If Mid(chaine, y, 1) = char Then x = x + 1
- Loop While x < nb And y <= Len(chaine)
- d = IIf(nb = 1, y, y + 1)
- y = y + 1
- While Mid(chaine, y, 1) <> char And y <= Len(chaine)
- y = y + 1
- Wend
- GetTok = Mid(chaine, d, (y - d))
- End Function
-
- Public Function InsTok(chaine As String, ins As String, nb As Integer, char As String)
- Dim x As Integer
- Dim result As String
- chaine = TrimTok(chaine, char)
- While x < (nb - 1)
- x = x + 1
- result = result & char & GetTok(chaine, x, char)
- Wend
- result = result & char & ins
- While x < NumTok(chaine, char)
- x = x + 1
- result = result & char & GetTok(chaine, x, char)
- Wend
- InsTok = TrimTok(result, char)
- End Function
-
- Public Function IsTok(chaine As String, ch As String, char As String)
- Dim x As Integer
- Dim y As Boolean
- chaine = TrimTok(chaine, char)
- For x = 1 To NumTok(chaine, char)
- If GetTok(chaine, x, char) = ch Then
- y = True
- IsTok = y
- End If
- Next x
- IsTok = y
- End Function
-
- Public Function NumTok(chaine As String, char As String)
- Dim x, y As Integer
- chaine = TrimTok(chaine, char)
- x = 1
- For y = 1 To Len(chaine)
- If Mid(chaine, y, 1) = char Then x = x + 1
- Next y
- NumTok = x
- End Function
-
- Public Function PutTok(chaine As String, ch As String, nb As Integer, char As String)
- Dim x As Integer
- Dim result As String
- chaine = TrimTok(chaine, char)
- While x < nb
- result = result & char & GetTok(chaine, x, char)
- x = x + 1
- Wend
- result = result & char & ch
- While x < NumTok(chaine, char)
- x = x + 1
- result = result & char & GetTok(chaine, x, char)
- Wend
- PutTok = TrimTok(result, char)
- End Function
-
- Public Function RemTok(chaine As String, ch As String, nb As Integer, char As String)
- chaine = TrimTok(chaine, char)
- RemTok = DelTok(chaine, FindTok(chaine, ch, nb, char), char)
- End Function
-
- Public Function RepTok(chaine As String, ch As String, nouv As String, nb As Integer, char As String)
- chaine = TrimTok(chaine, char)
- RepTok = PutTok(chaine, nouv, FindTok(chaine, ch, nb, char), char)
- End Function
-
- Public Function TrimTok(chaine As String, char As String)
- Dim x As Integer
- a:
- If Left(chaine, 1) = char Then chaine = Right(chaine, (Len(chaine) - 1))
- If Right(chaine, 1) = char Then chaine = Left(chaine, (Len(chaine) - 1))
- If Left(chaine, 1) = char Or Right(chaine, 1) = char Then GoTo a
- While x < Len(chaine)
- x = x + 1
- If Mid(chaine, x, 1) = char And Mid(chaine, x, 1) = Mid(chaine, x + 1, 1) Then
- chaine = Left(chaine, x) & Right(chaine, (Len(chaine) - x - 1))
- x = x - 1
- End If
- Wend
- TrimTok = chaine
- End Function
'Fonctions "TOKEN" ("marque") : fonctions de gestion de chaînes de caractères codées en VB6 par Tim alias HeXoR (hexor@wanadoo.fr - hexor47@hotmail.com) :)
'AddTok(...) ; DelTok(...) ; FindTok(...); GetTok(...) ; InsTok(...) ; IsTok(...) ; NumTok(...) ; PutTok(...) ; RemTok(...) ; RepTok(...) ; TrimTok(...)
'Dernière mise à jour le 05/03/2004 à 14h17 GMT+1
'Attention il est fortement conseillé d'insérer toutes les fonctions et non pas seulement celle qui vous intéresse car chaque de fonction a besoin des autres fonctions (à part TrimTok(...))
Public Function AddTok(chaine As String, add As String, char As String)
AddTok = TrimTok(chaine, char) & char & add
End Function
Public Function DelTok(chaine As String, nb As Integer, char As String)
Dim x As Integer
Dim result As String
chaine = TrimTok(chaine, char)
While x < nb
result = result & char & GetTok(chaine, x, char)
x = x + 1
Wend
While x < NumTok(chaine, char)
x = x + 1
result = result & char & GetTok(chaine, x, char)
Wend
DelTok = TrimTok(result, char)
End Function
Public Function FindTok(chaine As String, ch As String, nb As Integer, char As String)
Dim y As Integer
Dim x As Integer
chaine = TrimTok(chaine, char)
'y = 0
While y < nb
x = x + 1
If GetTok(chaine, x, char) = ch And nb = 1 Then FindTok = x
If GetTok(chaine, x, char) = ch Then y = y + 1
If y = nb Then FindTok = x
Wend
End Function
Public Function GetTok(chaine As String, nb As Integer, char As String)
Dim x, y, d As Integer
chaine = TrimTok(chaine, char)
x = 1
Do
y = y + 1
If Mid(chaine, y, 1) = char Then x = x + 1
Loop While x < nb And y <= Len(chaine)
d = IIf(nb = 1, y, y + 1)
y = y + 1
While Mid(chaine, y, 1) <> char And y <= Len(chaine)
y = y + 1
Wend
GetTok = Mid(chaine, d, (y - d))
End Function
Public Function InsTok(chaine As String, ins As String, nb As Integer, char As String)
Dim x As Integer
Dim result As String
chaine = TrimTok(chaine, char)
While x < (nb - 1)
x = x + 1
result = result & char & GetTok(chaine, x, char)
Wend
result = result & char & ins
While x < NumTok(chaine, char)
x = x + 1
result = result & char & GetTok(chaine, x, char)
Wend
InsTok = TrimTok(result, char)
End Function
Public Function IsTok(chaine As String, ch As String, char As String)
Dim x As Integer
Dim y As Boolean
chaine = TrimTok(chaine, char)
For x = 1 To NumTok(chaine, char)
If GetTok(chaine, x, char) = ch Then
y = True
IsTok = y
End If
Next x
IsTok = y
End Function
Public Function NumTok(chaine As String, char As String)
Dim x, y As Integer
chaine = TrimTok(chaine, char)
x = 1
For y = 1 To Len(chaine)
If Mid(chaine, y, 1) = char Then x = x + 1
Next y
NumTok = x
End Function
Public Function PutTok(chaine As String, ch As String, nb As Integer, char As String)
Dim x As Integer
Dim result As String
chaine = TrimTok(chaine, char)
While x < nb
result = result & char & GetTok(chaine, x, char)
x = x + 1
Wend
result = result & char & ch
While x < NumTok(chaine, char)
x = x + 1
result = result & char & GetTok(chaine, x, char)
Wend
PutTok = TrimTok(result, char)
End Function
Public Function RemTok(chaine As String, ch As String, nb As Integer, char As String)
chaine = TrimTok(chaine, char)
RemTok = DelTok(chaine, FindTok(chaine, ch, nb, char), char)
End Function
Public Function RepTok(chaine As String, ch As String, nouv As String, nb As Integer, char As String)
chaine = TrimTok(chaine, char)
RepTok = PutTok(chaine, nouv, FindTok(chaine, ch, nb, char), char)
End Function
Public Function TrimTok(chaine As String, char As String)
Dim x As Integer
a:
If Left(chaine, 1) = char Then chaine = Right(chaine, (Len(chaine) - 1))
If Right(chaine, 1) = char Then chaine = Left(chaine, (Len(chaine) - 1))
If Left(chaine, 1) = char Or Right(chaine, 1) = char Then GoTo a
While x < Len(chaine)
x = x + 1
If Mid(chaine, x, 1) = char And Mid(chaine, x, 1) = Mid(chaine, x + 1, 1) Then
chaine = Left(chaine, x) & Right(chaine, (Len(chaine) - x - 1))
x = x - 1
End If
Wend
TrimTok = chaine
End Function
Conclusion
Je pense ajouter d'autre fonctions. Donnez-moi votre avis, posez des questions si vous en avez, dites-moi si des bugs sont présents, besoin d'autres exemples ? -> commentaires :)
Sources du même auteur
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
[WP7] DYNAMICALLY CHANGE STARTUP PAGE[WP7] DYNAMICALLY CHANGE STARTUP PAGE par KooKiz
Let's say that you want to allow the user to customize the startup page of your application. You can easily change the startup page by editing the 'NavigationPage' attribute in the manifest file. But the manifest cannot be modified once the applicatio...
Cliquez pour lire la suite de l'article par KooKiz SESSION SILVERLIGHT 5 3D : SLIDES ET DEMOSSESSION SILVERLIGHT 5 3D : SLIDES ET DEMOS par Groc
Durant les techdays, j'ai eu le plaisir d'animer une session sur Silverlight 5 et la 3D avec Simon Ferquel. Comme promis, voici nos slides et mes démos (celles avec le viper BSG) ici et là. Pour mémoire, les démos utilisent toutes le viper BSG...
Cliquez pour lire la suite de l'article par Groc [TECHDAYS 2012] SESSION WEBMATRIX 2 : LE COUTEAU SUISSE GRATUIT POUR VOS DéVELOPPEMENTS WEB - SLIDES[TECHDAYS 2012] SESSION WEBMATRIX 2 : LE COUTEAU SUISSE GRATUIT POUR VOS DéVELOPPEMENTS WEB - SLIDES par gpommier
Suite à la session que j'ai présenté sur WebMatrix 2, vous pouvez trouver les slides ici, ainsi que les démos en packages nuget : démos1 et démos2 J'en profite pour remercier chaleureusement tous ceux qui sont venus très nombreux à cette sess...
Cliquez pour lire la suite de l'article par gpommier [SHAREPOINT] LES SESSIONS TECHDAYS 2012.[SHAREPOINT] LES SESSIONS TECHDAYS 2012. par Patrick Guimonet
Voici donc pour ceux qui n'ont pas pu venir, ou ceux qui n'ont pas pu toutes les suivre la liste des sessions SharePoint aux TechDays 2012, que je mettrais à jour dès que les liens des vidéo seront disponibles. Ou ici : http...
Cliquez pour lire la suite de l'article par Patrick Guimonet TECHDAYS PARIS 2012 : SESSION PLEINIèRE JOUR 3TECHDAYS PARIS 2012 : SESSION PLEINIèRE JOUR 3 par ROMELARD Fabrice
Speaker: Bernard Ourghanlian Cette session est comme chaque jour transmise en live par BrainSonic, et j'ai donc suivi cette troisième pleinière par ce moyen sur mon iPad . Elle est dédiée comme chaque année à la mise en perspective de l'é...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Forum
LISTER KEYS.KEYLISTER KEYS.KEY par Onin42
Cliquez pour lire la suite par Onin42
Logiciels
Tribler (2012)TRIBLER (2012)Tribler est un client pair à pair (P2P/Peer-to-Peer) open source avec la capacité de regarder des... Cliquez pour télécharger Tribler OneSwarm (2012)ONESWARM (2012)Le peer-to-peer qui protège votre vie privée, c'est OneSwarm.
Ce logiciel de peer-to-peer crypté... Cliquez pour télécharger OneSwarm PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System Easy-Planning (1.0.0.1)EASY-PLANNING (1.0.0.1)Basé sur les mêmes principes que MyPlanning, Easy-Planning permet de créer des plannings sous la ... Cliquez pour télécharger Easy-Planning
|