Hi,
How i can get a initial and final position of a word in a memo text without space?
Like this:
<cMun>TESTE<cMun><cCod>01213<cCod>AAAAAAAAAAAAAAAAAAAAA
In this case <cCod> starts in 18 and ending 23
Thanks.
#include "fivewin.ch"
FUNCTION MAIN()
// 123456789012345678901234567890123456789012345678901234567890
LOCAL cString := "<cMun>TESTE<cMun><cCod>01213<cCod>AAAAAAAAAAAAAAAAAAAAA"
LOCAL cWord := "<cCod>"
LOCAL aPos := {}
aPos := mypos( cString , cWord )
? aPos[1]
? aPos[2]
RETURN NIL
FUNCTION MYPOS( cString , cWord )
LOCAL nStart , nEnd
nStart := AT( cWord , cString ) // use RAT for last for right to left search
nEnd := nStart + LEN( cWord ) - 1
RETURN { nStart , nEnd }
MarcoBoschi wrote:
- Code: Select all Expand view
#include "fivewin.ch"
FUNCTION MAIN()
// 123456789012345678901234567890123456789012345678901234567890
LOCAL cString := "<cMun>TESTE<cMun><cCod>01213<cCod>AAAAAAAAAAAAAAAAAAAAA"
LOCAL cWord := "<cCod>"
LOCAL aPos := {}
aPos := mypos( cString , cWord )
? aPos[1]
? aPos[2]
RETURN NIL
FUNCTION MYPOS( cString , cWord )
LOCAL nStart , nEnd
nStart := AT( cWord , cString ) // use RAT for last for right to left search
nEnd := nStart + LEN( cWord ) - 1
RETURN { nStart , nEnd }
I find "<cCod>" 2 times in this string
#include "fivewin.ch"
FUNCTION MAIN()
// 1234567890123456789012345678901234567890123456789012345
LOCAL cString := "<cMun>TESTE<cMun><cCod>01213<cCod>AAAAAAAAAAAAAAAAAAAAA"
LOCAL cWord := "<cCod>"
LOCAL aPos := {}
LOCAL i
aPos := mypos( cString , cWord )
FOR i := 1 TO LEN( aPos )
? aPos[ i , 1 ] , aPos[ i , 2 ]
NEXT i
RETURN NIL
FUNCTION MYPOS( cString , cWord )
LOCAL aPos := {}
LOCAL i := 1
DO WHILE .T.
IF SUBSTR( cString , i , LEN( cWord ) ) = cWord
AADD( aPos , { i , i + LEN( cWord ) - 1 } )
i := i + LEN( cWord ) -1
ENDIF
IF i >= LEN( cString )
EXIT
ENDIF
i ++
ENDDO
RETURN aPos
NumAt()
Counts multiple occurrences of a substring within a string.
Syntax
NumAt( <cSearch> , ;
<cString> , ;
[<nSkipChars>] ) --> nCount
Arguments
<cSearch> This is a character string to search for in <cString>.
<cString> This is the character string to find <cSearch> in.
<nSkipChars> This numeric parameter defaults to 0 so that the function begins searching with the first character of <cString>. Passing a value > 0 instructs the function to ignore the first <nSkipChars> characters in the search. Return
The function returns the number of times <cSearch> is found in <cString> as a numeric value.
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 101 guests