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
UNE JOLIE-HORLOGE ET PAS QU'UN PEU !UNE JOLIE-HORLOGE ET PAS QU'UN PEU ! par neodante
Pour les possesseurs d'iPhone, ça y est Bijin Tokei - qui se traduit littéralement en Français par " Jolie Horloge " - est arrivé et GRATUITEMENT s'il vous plaît ! Après la version Tokyo, Hokkaido, night club, racing, Gal, "pour les mademoiselles'", . voi...
Cliquez pour lire la suite de l'article par neodante TECHDAYS PARIS 2010 : CONNECTEZ VOS DONNéES à SHAREPOINT 2010 AVEC LES BUSINESS CONNECTIVITY SERVICESTECHDAYS PARIS 2010 : CONNECTEZ VOS DONNéES à SHAREPOINT 2010 AVEC LES BUSINESS CONNECTIVITY SERVICES par ROMELARD Fabrice
Animé par: Gaetan Bouveret et Julien Chomarat Business Connectivity Services (BCS) est dans SharePoint 2010 la version 2 de Business Data Catalog (BDC dans SharePoint 2007). Il s'agit de la solution permettant de visualiser des données provenan...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice [DIVERS] SUIVRE VOS SéRIES PRéFéRéS SUR LA TOILE[DIVERS] SUIVRE VOS SéRIES PRéFéRéS SUR LA TOILE par orion
Comme de nombreux geek, je suis un grand amateur de série TV et je rate régulièrement des épisodes de mes séries préférés. Une solution s'offre à vous avec ce merveilleux site : Tv Gorge - www.tvgorge.com Moteur de recherche à l'appui, vous pouvez ...
Cliquez pour lire la suite de l'article par orion TECHDAYS PARIS 2010 : LA BI DANS SHAREPOINT 2010TECHDAYS PARIS 2010 : LA BI DANS SHAREPOINT 2010 par ROMELARD Fabrice
Animé par: Vincent Bellet et Baptiste Giraudier La BI dans SharePoint 2010, Les nouveaux services d'application dans SP2010 et SQL Server Reporting services 2008 R2. La BI dans SharePoint est généralisée pour tous afin de permettre à tous les coll...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Logiciels
DB-MAIN (9.1.0)DB-MAIN (9.1.0)DB-MAIN is a data-modeling and data-architecture tool. It is designed to help developers and anal... Cliquez pour télécharger DB-MAIN Xilisoft DPG Convertisseur (5.1.37.0120)XILISOFT DPG CONVERTISSEUR (5.1.37.0120)Xilisoft DPG Convertisseur offre aux fans de Nintendo DS une bonne solution leur permettant de dé... Cliquez pour télécharger Xilisoft DPG Convertisseur GraphicsGale (2.01.01)GRAPHICSGALE (2.01.01)GraphicsGale est un logiciel de PixelArt avec de nombreuse fonctionnalités permettant de réalisé ... Cliquez pour télécharger GraphicsGale Architecte 3D (Platinum 2010)ARCHITECTE 3D (PLATINUM 2010)Architecte 3D Platinium vous permet de concevoir facilement les plans votre future maison, de l'é... Cliquez pour télécharger Architecte 3D TeamViewer 5 (TeamViewer 5)TEAMVIEWER 5 (TEAMVIEWER 5)Dépanner un ami,expliquer une manipulation devient un jeu d'enfant.
Prise en main d'un autre ord... Cliquez pour télécharger TeamViewer 5
|