Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
For each line in string variable
Message
From
04/05/2006 16:33:31
 
 
To
04/05/2006 16:29:03
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, United States
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 7 SP1
Miscellaneous
Thread ID:
01119378
Message ID:
01119383
Views:
13
>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 Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform