Newsgroup: it.comp.lang.visual-basic
Titolo: Algoritmo sostituzione stringhe in testo

Qualcuno puo aiutarmi a trovare un algoritmo che permetta di elaborare un
testo sostituendo in esso delle stringhe con altre presenti in una tabella
di riferimento ?
Es. se nel testo trovo "al riguardo" voglio sostituirlo con "al_riuardo".
Grazie.
Marco SILVESTRI

 wrote in message
news:UAH36.2625$jT6.1...@twister2.tin.it...

Funzione Replace()
Ciao
Aldo

 Funzione Replace()
Se ha il VB5 non c'è...
Nel caso usa questa:
__________________________
Public Function ReplacePublic Function Replace(ByVal Expression As String, ByVal FindString As String, ByVal ReplaceString As
String, _
                        Optional ByVal Start As Long = 1, Optional ByVal ReplaceCount As Long = -1, _
                        Optional ByVal Compare As VbCompareMethod = vbBinaryCompare) As String
'===============================================================================
'   Replace - This function mimics the VBA6.Replace function which is not
'   available in VB5. This function helps VB5 & VB6 projects co-exist.
'
'   NOTE: Note, anyone making adjustments to this function should keep in
'   mind that it is intended to behave EXACTLY like the VBA6.Replace
'   function (flaws and all, including operands).
'
'   Expression      String to be searched.
'   FindString      String being sought.
'   ReplaceString   Replacement substring.
'   Start           Optional. Position within expression where substring
'                   search is to begin. If omitted, 1 is assumed.
'   ReplaceCount    Optional. Number of substring substitutions to perform.
'                   If omitted, the default value is –1, which means make
'                   all possible substitutions.
'   Compare         Optional. Numeric value indicating the kind of comparison
'                   to use when evaluating substrings. See Settings section
'                   for values.
'===============================================================================
Dim FindLen     As Long     ' length of search string
Dim Pos         As Long     ' position where search string located
Dim nCount      As Long     ' # of replacements
    On Error GoTo ErrHandler                            ' trap all errors
    FindLen = Len(FindString)                           ' ID length of search string
    Pos = 1                                             ' initialize the loop
    Do While Pos > 0
        Pos = InStr(Pos, Expression, FindString)        ' locate search string
        'Found, Is the string being replaced the same length as the search string
        'If not I must divide the string at the search string position
        If Pos > 0 Then                                 ' substring found
            nCount = nCount + 1
            Expression = Left$(Expression, Pos - 1) & _
                ReplaceString & _
                Mid$(Expression, Pos + FindLen)         ' make the replacement
        End If
        If nCount = ReplaceCount Then Exit Do           ' exit loop if max replacements reached
    Loop
ExitLabel:
    ' Return the result
    Replace = Expression
Exit Function
Resume
ErrHandler:
    Debug.Print Err.Description: Debug.Assert 0
    Resume ExitLabel
End Function
___________________________
Bye, G.
--
---------------------------------------------
    Le risposte alle tue domande le trovi
    sul Sito Comune di questo NewsGroup:
 
http://www.murialdo.it/it_lang_vb
       ... e nell'help in linea !
---------------------------------------------
Real E-address: gaetano_d(AT)
hotmail.com

 Nel caso usa questa:
...(...)...
Giusto, non ci avevo pensato !
Ciao
Aldo

 Giusto, non ci avevo pensato !
Noi del '61 in questi giorni abbiamo altro per la testa.
Io almeno fino all'8 febbraio... :-))
By, G.