Search by line
Search by line
Is there a search function for a line with a code block (a la ascan() ) ?
- Antonio Linares
- Site Admin
- Posts: 42259
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: Search by line
Do you want to get each line or only a line that matches with a given one ?
- nageswaragunupudi
- Posts: 10691
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Contact:
Re: Search by line
Esto?
Regards, saludos.
Code: Select all | Expand
/*
* Project: xFF - PESQTEXT.PRG \samples
* File: xFF.prg
* Description:
* Author: JMSilva
* Date: 06-25-2014
*/
#Include "FiveWin.ch"
FUNCTION Main()
LOCAL oFont, oDlg, oMemo, oBtnSair, oIco, oBrush
LOCAL oKey, cKey := Space( 20 ), oBtnFind, cText
DEFINE BRUSH oBrush STYLE "BORLAND"
DEFINE FONT oFont NAME "TAHOMA" SIZE 00, -14 BOLD
DEFINE DIALOG oDlg TITLE "Pesquisa com GET TEXT" ;
SIZE 680, 480 BRUSH oBrush FONT oFont ;
STYLE nOR( WS_SYSMENU, WS_MINIMIZEBOX )
oDlg:lHelpIcon := .F.
cText := MemoRead( "Teste.txt" ) // pode ser campo memo
@ 4, 3 GET oMemo VAR cText MEMO OF oDlg PIXEL SIZE 330, 192 FONT oFont
oMemo:bGotFocus := {|| oMemo:SetSel( 0, 0 ) }
oMemo:lReadOnly := .T. // nÆo edita
@ 14, 1 SAY "PESQUISA:" COLOR CLR_HBLUE TRANSPARENT
IF Set( _SET_INSERT, ! Set( _SET_INSERT ) )
Set( _SET_INSERT, ! Set( _SET_INSERT ) )
ENDIF
@ 16, 5 GET oKey VAR cKey PICTURE "@!" ;
ACTION ( Find( oMemo, Trim( cKey ), .T. ), oBtnFind:Enable() )
oKey:bKeyChar := {|| oBtnFind:Disable() }
@ 204, 120 BTNBMP oBtnFind PROMPT "&Próximo" SIZE 40, 18 CENTER 2007 ;
ACTION Find( oMemo, Trim( cKey ), .F. ) WHEN Find()
oBtnFind:Disable()
@ 204, 290 BTNBMP oBtnSair PROMPT "&Sair" SIZE 40, 18 CENTER 2007 ;
ACTION( oDlg:End() )
oBtnSair:lCancel := .T.
ACTIVATE DIALOG oDlg CENTERED ON INIT( xFocus( oKey ) )
IF Set( _SET_INSERT, ! Set( _SET_INSERT ) )
Set( _SET_INSERT, ! Set( _SET_INSERT ) )
ENDIF
oBrush:End()
oFont:End()
RETURN NIL
FUNCTION Find( oMemo, cFind, lNew )
LOCAL nIndex := 0
STATIC nStart := 0
IF PCount() == 0 ; RETURN( nStart > 0 ) ; ENDIF // when
IF lNew ; nStart := 1; ENDIF // start
nIndex := At( Trim( cFind ), Upper( oMemo:cText ), nStart, Len( oMemo:cText ) )
IF nIndex > 0
oMemo:Setfocus() // seta o focu
oMemo:SetPos( nIndex - 1, nIndex ) // posiciona
oMemo:SetSel( nIndex - 1, nIndex + Len( Trim( cFind ) ) - 1 )
RESetSelection( oMemo:hWnd, nIndex + Len( Trim( cFind ) ), nIndex ) // faz a rolagem do texto
oMemo:Change()
nSTART := nIndex + Len( Trim( cFind ) )// para continuar a pesquisa
ELSEIF lNew
MsgStop( "A palavra: " + cFind + " não foi localizada", "Find" )
oMemo:SetSel( 0, 0 )
nStart := 1
ELSE
MsgStop( "Nenhuma outra ocorrência foi encontrada", "Find" )
nIndex := nStart - Len( Trim( cFind ) )
oMemo:SetPos( nIndex - 1, nIndex ) // posiciona
ENDIF
RETURN( .T. )
//-------------------------------------------------------------------------//
// As vezes simples SetFocus( oObj ) nao faz um objeto ganhar foco
// neste caso pode apelar para estas duas funcoes a seguir
// Forcar foco para um objeto especifico - Ednaldo Rolim...
//-------------------------------------------------------------------------//
FUNCTION xFocus( oObj )
xSetFocus( oObj )
xSetFocus( oObj )
RETURN( .T. )
FUNCTION xSetFocus( oObj )
LOCAL _oWnd := oObj:oWnd, _oTempo := ""
DEFINE TIMER _oTempo INTERVAL 10 OF _oWnd ;
ACTION ( oObj:SetFocus(), _oTempo:End() )
ACTIVATE TIMER _oTempo
RETURN( .T. )
// FIN / END
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Re: Search by line
I needed to find out if the string consists only of numbers or not. I wrote such a function:
if AtLine(adr, "{|xx|asc(xx)<48.or.asc(xx)>57}")=0
...............................................
endif
function AtLine(itm, xBk)
local st, nOk:=0
** itm - string
** xBk - code block
xBk:=&xBk
for st=1 to len(itm)
if eval(xBk, itm[st])
nOk:=st
exit
endif
next
return nOk
It works fine, but I wanted to know if there is already a similar function
if AtLine(adr, "{|xx|asc(xx)<48.or.asc(xx)>57}")=0
...............................................
endif
function AtLine(itm, xBk)
local st, nOk:=0
** itm - string
** xBk - code block
xBk:=&xBk
for st=1 to len(itm)
if eval(xBk, itm[st])
nOk:=st
exit
endif
next
return nOk
It works fine, but I wanted to know if there is already a similar function
Re: Search by line
You could use regex function HB_RegEx().
Re: Search by line
Algo asi?
Regards, saludos.
Code: Select all | Expand
#include "FiveWin.ch"
FUNCTION Main()
? VerString( "001432 DAIANE 5555 OLIVEIRA UBA" )
RETURN NIL
FUNCTION VerString( cStr )
LOCAL cStrNova := ""
LOCAL nCt := 0, n1
FOR n1 := 1 TO Len( AllTrim( cStr ) )
IF .NOT. IsAlpha( SubStr( cStr, n1, 1 ) ) .AND. .NOT. ;
Empty( SubStr( cStr, n1, 1 ) )
nCt++
IF nCt <= 3
cStrNova += SubStr( cStr, n1, 1 ) // conta os primeiros 3 digitos.
// ? cStrNova
ENDIF
ELSE
cStrNova += SubStr( cStr, n1, 1 ) // conta somente as letras.
// ? cStrNova
ENDIF
NEXT n1
// ? cStrNova
Return( cStrNova )
// FIN / END
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Re: Search by line
Thanks, Detlef! Where can I see the description of the HB_RegEx() function ?
Re: Search by line
If you give me your email adress I will send you the docs.