VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clibString"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit

'////////////////////////////////////////////////////////////////////////////////////
'// Class Librairie STRING                                                         //
'// Auteur:   Jerome                                                               //
'// Pour:     Le pape & Co                                                         //
'// Version:  V 1.0                                                                //
'// Date:     29 Juin 1999                                                         //
'// Projet:   exPand BlocNote                                                      //
'////////////////////////////////////////////////////////////////////////////////////

'// cette classe contient une librairie
'   d'acces aux fonctions de manipulations de chaines de caracteres

'// utilitaires globaux pour la manipulation des chaines de caracteres
'V1.1 7 juillet 1998  ajout de cleanStr pour nettoyer les caracteres invisibles
'V1.2 25 Aout 1998  ajout de GrabLastWord LastStr et strRemplace
'V1.3 10 Decembre 1998 ajour FindLastWord
'// Version:  V1.4                                                                 //
'grabfirstword & grablastword decoupe correctement si le separateur
'fait plus d'un  caractere
'// Version:  V1.5                                                                 //
'passage sous VB6  RAS
'V1.4 02 Aout 1999 Correction GrapFirstWord & GrapLastWord
'Utilisation Sep a lieu de aSeparator

'V1.5 transformation de cette classe en DLL

Public Function GetFnameN(afname As String) As String
Attribute GetFnameN.VB_Description = "Donne la partie NNN d'un   path PPP\\NNN.EEE"
' Donne la partie NNN d'un   path PPP\NNN.EEE
  Dim T As String
  Dim N As Integer
  Dim n1 As Integer
  N = 1
  Do While N < Len(afname)
    n1 = InStr(N, afname, "\")
    If n1 = 0 Then Exit Do
    N = n1 + 1
  Loop
  T = Mid(afname, N) & "."
  n1 = InStr(T, ".")
  GetFnameN = Mid(T, 1, n1 - 1)
End Function

Public Function GetFnameP(ByVal afname As String) As String
Attribute GetFnameP.VB_Description = "Donne la partie PPP d'un   path PPP\\NNN.EEE"
' Donne la partie PPP d'un   path PPP\NNN.EEE
  Dim T As String
  Dim N As Integer
  Dim n1 As Integer
  
  'GetFnameP = ""
  If InStr(afname, "\") = 0 Then Exit Function
  N = 1
  Do While N < Len(afname)
    n1 = InStr(N, afname, "\")
    If n1 = 0 Then Exit Do
    N = n1 + 1
  Loop
  GetFnameP = Mid(afname, 1, N - 2)
End Function

Public Function GetFnameNE(ByVal afname As String) As String
Attribute GetFnameNE.VB_Description = "Donne la partie NNN.EEE d'un   path PPP\\NNN.EEE"
' Donne la partie NNN.EEE d'un   path PPP\NNN.EEE
  Dim N As Integer
  Dim n1 As Integer
  
  N = 1
  Do While N < Len(afname)
    n1 = InStr(N, afname, "\")
    If n1 = 0 Then Exit Do
    N = n1 + 1
  Loop
  GetFnameNE = Mid(afname, N)
End Function

Public Function GetFnameE(ByVal afname As String) As String
Attribute GetFnameE.VB_Description = "Donne la partie EEE d'un   path PPP\\NNN.EEE"
' Donne la partie EEE d'un   path PPP\NNN.EEE
  Dim N As Integer
  Dim n1 As Integer
  
  If InStr(afname, ".") = 0 Then Exit Function
  N = 1
  Do While N < Len(afname)
    n1 = InStr(N, afname, ".")
    If n1 = 0 Then Exit Do
    N = n1 + 1
  Loop
  GetFnameE = Mid(afname, N)
End Function

Public Function getFnamePN(ByVal afname As String) As String
Attribute getFnamePN.VB_Description = "Donne la partie PPP\\NNN d'un   path PPP\\NNN.EEE "
' Donne la partie PPP\NNN d'un   path PPP\NNN.EEE
  Dim N As Integer
  Dim n1 As Integer
  
  getFnamePN = afname
  If InStr(afname, ".") = 0 Then Exit Function
  N = 1
  Do While N < Len(afname)
    n1 = InStr(N, afname, ".")
    If n1 = 0 Then Exit Do
    N = n1 + 1
  Loop
  getFnamePN = Mid(afname, 1, N - 2)
End Function

Public Function getFnameD(ByVal afname As String) As String
Attribute getFnameD.VB_Description = "Donne la partie D d'un   path D:PPP\\NNN.EEE"
' Donne la partie D d'un   path D:PPP\NNN.EEE
  Dim N As Integer
  Dim n1 As Integer
  
  If InStr(afname, ":") = 0 Then Exit Function
  N = 1
  Do While N < Len(afname)
     n1 = InStr(N, afname, ":")
    If n1 = 0 Then Exit Do
    N = n1 + 1
  Loop
  getFnameD = Mid(afname, 1, N - 2)
End Function

Public Function GrabFirstWord(ByRef atext As String, Optional aSeparator As Variant) As String
Attribute GrabFirstWord.VB_Description = "decoupe le premier mot de la chaine aText"
'decoupe le premier mot de la chaine aText
'decoupe correctement si le seperateur fait plus d'un caractere
  Dim N As Integer
  Dim Sep As String
  
  atext = LTrim(atext) 'supression des blancs devant
  If IsMissing(aSeparator) Then
    Sep = " "
  Else
    Sep = aSeparator
  End If
  N = InStr(atext, Sep)
  If N = 0 Then
    GrabFirstWord = atext
    atext = ""
    Exit Function
  End If
  GrabFirstWord = Left(atext, N - 1)
  atext = Mid(atext, N + Len(Sep))
End Function

Public Function GrabFirstWord_tab(ByRef atext As String, Optional aSeparator As Object) As String
'decoupe le premier mot de la chaine aText
'decoupe correctement si le seperateur fait plus d'un caractere
  Dim N As Integer
  Dim Sep As String
  
  atext = LTrim(atext) 'supression des blancs devant
  If IsMissing(aSeparator) Then
    Sep = " "
  Else
    Sep = aSeparator
  End If
  N = InStr(atext, Sep)
  If N = 0 Then
    GrabFirstWord_tab = atext
    atext = ""
    Exit Function
  End If
  GrabFirstWord_tab = Left(atext, N - 1)
  atext = Mid(atext, N + Len(Sep))
End Function

Public Function CleanPath(astr As String) As String
Attribute CleanPath.VB_Description = "retire le '\\' a un path si il y en a un"
'retire le '\' a un path si il y en a un
  If (Right(astr, 1) = "\") Then
    CleanPath = Left(astr, Len(astr) - 1)
  Else
    CleanPath = astr
  End If
End Function

Public Sub StrRemplace(astr As String, modele As String, remplacement As String)
Attribute StrRemplace.VB_Description = "remplace toute les occurences de la chaine modele par la chaine remplacement"
'// remplace toute les occurences de la chaine modele par la chaine remplacement
'   la chaine de remplacement n'est pas scrutée
  Dim n1 As Integer
  n1 = 1
  If modele = "" Then Exit Sub
  Do
    n1 = InStr(n1, astr, modele, 1)
    If n1 = 0 Then Exit Do
    astr = Left(astr, n1 - 1) + remplacement + Mid(astr, n1 + Len(modele))
    n1 = n1 + Len(remplacement)
  Loop
End Sub

Public Function StrCompte(astr As String, modele As String) As Integer
'// Compte le nombre d'aucurance de Modele dans astr
  Dim n1 As Integer
  n1 = 1
  If modele = "" Then Exit Function
  Do
    n1 = InStr(n1, astr, modele, 1)
    If n1 = 0 Then Exit Do
    StrCompte = StrCompte + 1
    n1 = n1 + 1
  Loop
End Function

Public Function GrabLastWord(ByRef atext As String, Optional aSeparator As Variant) As String
Attribute GrabLastWord.VB_Description = "decoupe le dernier de la chaine aText"
'decoupe le dernier de la chaine aText
  Dim N As Integer
  Dim Sep As String
  
  atext = LTrim(atext) 'supression des blancs devant
  If IsMissing(aSeparator) Then
    Sep = " "
  Else
    Sep = aSeparator
  End If
  N = LastStr(atext, Sep)
  If N = 0 Then
    GrabLastWord = atext
    atext = ""
    Exit Function
  End If
  GrabLastWord = Mid(atext, N + Len(Sep))
  atext = Left(atext, N - 1)
End Function

Private Function LastStr(atext As String, aOccurence As String) As Integer
' equivalent a instr du vb mais se base sur la derniere occurence
  Dim N As Integer
  Dim L As Integer
  L = Len(aOccurence)
  N = Len(atext) - L + 1
  While N > 0
    If Mid(atext, N, L) = aOccurence Then
      LastStr = N
      Exit Function
    End If
    N = N - 1
  Wend
  LastStr = 0
End Function

Public Function FindLastWord(Chaine As String, Separator As String, ByRef pos As Integer) As String
Attribute FindLastWord.VB_Description = "Routine permettant de retrouver le dernier mot d'une chaine"
'Routine permettant de retrouver le dernier mot d'une chaine
Dim StrPos As Integer
Dim ancStrPos As Integer
Dim LenFolder As Integer

    If pos = 0 Then
        pos = 1
    End If
    LenFolder = Len(Chaine)
    ancStrPos = pos  'début de la chaine
    
    'Recherche du dernier nom de la chaine 'chaine'
    Do
        StrPos = InStr(ancStrPos, Chaine, Separator, vbTextCompare)
        If StrPos <> 0 Then ancStrPos = StrPos + 1 'sauvegarde de l'ancienne position
    Loop While StrPos <> 0
    pos = ancStrPos + 1
    FindLastWord = Right(Chaine, (LenFolder - ancStrPos) + 1)
End Function

