On what lines does a string occur?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: On what lines does a string occur?

  1. #1
    William Fields Guest

    On what lines does a string occur?

    I'm trying to determine all the lines where a string occurs in a memo field
    or other string and I'm coming up blank. I could loop through all the lines
    to determine this, but is there a simple function call that lets me search
    by occurrence instead? The reason I need the line number is that I want to
    manipulate the entire line, not just the string I'm searching for.

    Of course, AtLine() tells you the first occurrence, but how about the rest
    of them?

    --
    William Fields
    MCP - Microsoft Visual FoxPro
    US Bankruptcy Court
    Phoenix, AZ





  2. #2
    Anders Altberg Guest

    Re: On what lines does a string occur?

    hard to say. Will this do?

    lcSearchString='...'
    FOR i = 1 TO OCCURS(lcSearchString,MText)
    ? MLINE(MTEXT,ATC(lcSearchString, MText, i) )
    NEXT

    "William Fields" <Bill_Fields@azb.uscourts.gov> wrote in message
    news:39176294@news.devx.com...
    > I'm trying to determine all the lines where a string occurs in a memo

    field
    > or other string and I'm coming up blank. I could loop through all the

    lines
    > to determine this, but is there a simple function call that lets me search
    > by occurrence instead? The reason I need the line number is that I want to
    > manipulate the entire line, not just the string I'm searching for.
    >
    > Of course, AtLine() tells you the first occurrence, but how about the rest
    > of them?
    >
    > --
    > William Fields
    > MCP - Microsoft Visual FoxPro
    > US Bankruptcy Court
    > Phoenix, AZ
    >
    >
    >
    >




  3. #3
    Anders Altberg Guest

    Re: On what lines does a string occur?

    Hi again
    Here's a more useful answewr to this problem I hope.
    What a line in a memo, editbox or string? If you want to the lines you see
    in an editbox you have to find a MemoWidth setting such that each MLINE()
    exactly matches the rows you see. Given that and given that the lines where
    your searchvalue is found are different from other rows containing the
    searchstring you could get the row numbers in a loop. Suppose we're looking
    for occurances of "123" in eb.value
    for i = 1 to memlines(eb.value)
    if '123' $ mline(eb.value,i)
    * debugout mline(eb.value,i)
    debugout atcline(mline(eb.value,i),eb.value)
    endif
    next
    I hope there are better ways. With word-wrapped text it's very tricky.
    Getting the offsets for the searchstring is supported by AT()
    FOR i = 1 TO OCCURS('123',eb.text)
    ? ATC('123', eb.text, i)
    NEXT

    -Anders

    "William Fields" <Bill_Fields@azb.uscourts.gov> wrote in message
    news:39176294@news.devx.com...
    > I'm trying to determine all the lines where a string occurs in a memo

    field
    > or other string and I'm coming up blank. I could loop through all the

    lines
    > to determine this, but is there a simple function call that lets me search
    > by occurrence instead? The reason I need the line number is that I want to
    > manipulate the entire line, not just the string I'm searching for.
    >
    > Of course, AtLine() tells you the first occurrence, but how about the rest
    > of them?
    >
    > --
    > William Fields
    > MCP - Microsoft Visual FoxPro
    > US Bankruptcy Court
    > Phoenix, AZ
    >
    >
    >
    >




  4. #4
    William Fields Guest

    Re: On what lines does a string occur?

    Thanks a lot Anders. In particular, I'm interested in actual memo fields or
    string variables. This should get me where I need to go.

    --
    William Fields
    MCP - Microsoft Visual FoxPro
    US Bankruptcy Court
    Phoenix, AZ


    "Anders Altberg" <anders.altberg@swipnet.se> wrote in message
    news:3917e104$1@news.devx.com...
    > Hi again
    > Here's a more useful answewr to this problem I hope.
    > What a line in a memo, editbox or string? If you want to the lines you see
    > in an editbox you have to find a MemoWidth setting such that each MLINE()
    > exactly matches the rows you see. Given that and given that the lines

    where
    > your searchvalue is found are different from other rows containing the
    > searchstring you could get the row numbers in a loop. Suppose we're

    looking
    > for occurances of "123" in eb.value
    > for i = 1 to memlines(eb.value)
    > if '123' $ mline(eb.value,i)
    > * debugout mline(eb.value,i)
    > debugout atcline(mline(eb.value,i),eb.value)
    > endif
    > next
    > I hope there are better ways. With word-wrapped text it's very tricky.
    > Getting the offsets for the searchstring is supported by AT()
    > FOR i = 1 TO OCCURS('123',eb.text)
    > ? ATC('123', eb.text, i)
    > NEXT
    >
    > -Anders
    >
    > "William Fields" <Bill_Fields@azb.uscourts.gov> wrote in message
    > news:39176294@news.devx.com...
    > > I'm trying to determine all the lines where a string occurs in a memo

    > field
    > > or other string and I'm coming up blank. I could loop through all the

    > lines
    > > to determine this, but is there a simple function call that lets me

    search
    > > by occurrence instead? The reason I need the line number is that I want

    to
    > > manipulate the entire line, not just the string I'm searching for.
    > >
    > > Of course, AtLine() tells you the first occurrence, but how about the

    rest
    > > of them?
    > >
    > > --
    > > William Fields
    > > MCP - Microsoft Visual FoxPro
    > > US Bankruptcy Court
    > > Phoenix, AZ
    > >
    > >
    > >
    > >

    >
    >




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center