Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
For each line in string variable
Message
De
04/05/2006 17:10:49
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
04/05/2006 16:33:31
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 7 SP1
Divers
Thread ID:
01119378
Message ID:
01119411
Vues:
20
>>I have a string variable complete with line breaks and carriage returns. Is there a way I can create a loop for each line in that variable? I need to offset each line by 1 space, and I think this loop is the only way of doing it.
>
>It could be processed as we process a memo field. You could use MemLines() and _MLINE. It might require however that you create a temporary cursor with one record and one field. You could make that field of type Memo and dump your string in it. Then, MemLines() and _MLINE would work.
>
>Yesterday, however, I did a function in VB.NET that does that. It receives a string, which contains several carriage returns, and return the desired line. You could easily transfer that in VFP and adjust as needed:
>
>
>        ' Return the number of lines in a string
>        ' expC1 String
>        Public Function MemLines(ByVal tcValue As String) As Integer
>            Dim lcValue As String = ""
>            Dim lnLine As Integer = 0
>            lcValue = tcValue
>            lnLine = oApp.Occurs(oApp.cCR, lcValue) + 1
>            Return lnLine
>        End Function
>
>        ' Return the specific line in a string
>        ' expC1 String
>        ' expN1 Line
>        Public Function MLine(ByVal tcValue As String, ByVal tnLine As Integer) As String
>            Dim lcLine As String = ""
>            Dim lcValue As String = ""
>            Dim lcValueAdjusted As String = ""
>            Dim lnLine As Integer = 0
>            Dim lnLocation As Integer = 0
>            lcValue = tcValue
>            lnLine = oApp.Occurs(oApp.cCR, lcValue) + 1
>
>            ' If the line requested is greather than the number of lines
>            If tnLine > lnLine Then
>                Return ""
>            End If
>
>            ' If we are requesting the first ilne
>            If tnLine = 1 Then
>
>                ' See if we have more than one line
>                If lnLine > 1 Then
>                    lcLine = Mid(lcValue, 1, InStr(lcValue, oApp.cCR) - 1)
>                Else
>                    lcLine = tcValue
>                End If
>
>            Else
>
>                ' Make sure we are about to find a carriage return
>                lnLocation = oApp.At(oApp.cCR, lcValue, tnLine - 1)
>                If lnLocation > 0 Then
>                    lcValueAdjusted = Mid(lcValue, oApp.At(oApp.cCR, lcValue, tnLine - 1) + 2)
>
>                    ' If this is not the last line
>                    lnLocation = InStr(lcValueAdjusted, oApp.cCR)
>                    If lnLocation > 0 Then
>                        lcLine = Mid(lcValueAdjusted, 1, InStr(lcValueAdjusted, oApp.cCR) - 1)
>                    Else
>                        lcLine = lcValueAdjusted
>                    End If
>
>                Else
>                    lcLine = ""
>                End If
>            End If
>
>            Return lcLine
>        End Function
>
>
>When I did it, the goal was to simulate the VFP function in .NET. I see you could use something out of it.

Michel,
FYI side note. memlines and mline() do not require a memo field.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform