Name:
flocate() - locate text in a text file
_xkey() - specify no abort in flocate()
_xkeyval() - specify key that aborts flocate()
Usage:
[<integer>] = flocate(<handle>,<string>,[<case>])
[<logical>] = _xkey([<logical>])
[<key>] = _xkeyval(<key>)
Params:
integer <handle> from a previous fopen() or fcreate()
string <string> - the string to locate in the file
logical <case> - optional case specifier. If <case>
is .T., then the text of the file is converted to uppercase
before it is compared to <string>, If <case> is false,
then the text is converted to lowercase before it is
compared to <string>. If this parameter is left off,
then the text is left as is. To search for non case
sensitive text, use the appropriate <case> value, and
then convert the string to be searched for to either upper
or lower case. Note that converting the text in the file
to either upper or lower case does not modify the text in
the file.
_xkey() tells flocate() if the user is allowed to abort
an flocate() search via an ESCape key. _xkeyval() tells
flocate() what the ESCape key is. The default value for
_xkey() is always .T. (aborting allowed). the default
abort key is ESCape (27) until you redefine it._xkey()
parameters are logical .T. to turn user abort on, .F.
to turn it off. _xkeyval() parameters are any valid
inkey() value that you want the abort key to be. The
default is to have abort capability on using ESCape.
Returns:
integer equal to the offset of the first byte of the
found string. The file pointer is positioned on the
first letter of the found string. if a read error occurs
flocate() returns a -1. If the string is not found, a -2
is returned and the pointer is returned to the position where
it started the search. If the user aborted the search, a
-3 is returned and the pointer is returned to the position
where it started the search.
If no parameters are sent to _xkey() it returns the
current state of the _xkey() flag - .T. equals on, .F.
equals off. _xkeyval() returns the current abort key
value as an integer.
---------------------------------------- Example --------------------
- Code: Select all Expand view
use names
handle = fopen("names.txt")
offset = flocate(handle,"dLESKO")
if offset < 0
? "text not found...."
else
m_name = freadline(handle)
m_address = freadline(handle)
m_city = freadline(handle)
m_state = freadline(handle)
m_zip = freadline(handle)
replace name with m_name,;
address with m_address,;
city with m_city,;
state with m_state,;
zip with m_zip
endif
fclose(handle)
close databases
Note: Searching takes a about 1 second per 50k of file depending
on type of machine used. If a no find occurs, (-2 or -3)
the file pointer is left where it started. If a read
error occurs (-1), then the file pointer can be anywhere.
flocate() starts the search starting at the current
pointer position and stops at the first occurrence of
the found string. To search for multiple occurrences, find
the first occurrence, freadstr() or fseek() past it, and
start searching for the next occurrence.
JmGarcia wrote:La última versión 6 NO la tiene.
Locate
Locate a string of text in the file
--------------------------------------------------------------------------------
FUNCky 6.0®
COM Component
--------------------------------------------------------------------------------
Syntax
obj.Locate( Str [, Flag ] )
Part
--------------------------------------------------------------------------------
Description
--------------------------------------------------------------------------------
obj A File object returned from a previous call to FUNCky.CreateFile.
Str The string of text to look for.
Flag The case sensitivity to use. Optional. If omitted, TRUE is assumed.
Returns
The file pointer position where the first matching string was found, -1 if an error occurred, -2 if the string was not found.
Description
Locate searches the current file for a specific string of text. The search begins at the current file pointer position and ends when the first occurrence of the string is found, or when the end of file is reached, whichever comes first.
The string to search for is specified via the parameter Str.
The case sensitivity of the search can be specified via the parameter Flag.
When Flag is True, a case sensitive search is performed.
When Flag is False, a non-case sensitive searched is performed.
If Flag is not specified, True is assumed.
If the specified string is found, the file pointer is positioned on the first character in the found string and its offset within the file is returned.
If the specified string is not found, -2 is returned and the file pointer position is unchanged.
If an error occurred while searching for the string, -1 is returned and the file pointer is left in an undetermined position.
If an error occurs, the Error and ErrorMessage properties can be queried for more detailed information.
--------------------------------------------------------------------------------
Tip Use the Skip method to rewind the file pointer to the beginning of the line of text where the string is found so that the whole line of text including the string may be read.
To search for multiple occurrences of text, find the first occurrence, then add the length of the found string to the Offset property to skip over it. Then just repeat the search.
--------------------------------------------------------------------------------
Example
- Code: Select all Expand view
// This example opens a file, searches for the
// word "Gadzooks", and if found, the file
// pointer is rewound to the start of the line
// to read the whole line of text containing the word
Set File = FUNCky.CreateFile()
// Open some text file
If( File.Open("C:\SomeFile.txt", FConst.O_READONLY)) Then
// Locate the word "Gadzooks" using no case sensitivity
Offset = File.Locate("Gadzooks", False )
// Verify found
If( Offset >= 0) Then
// Rewind to the beginning of the line
Offset = File.Skip(0)
// Read in that line of text
Str = File.ReadLine()
End If
// All done with file
File.Close()
End If
No hay que linkar nada. Solo instalar los que ellos llaman "REDISTRIBUTABLES" y se te queda instalado en el PC la tecnología COM (Common Object Model).antolin wrote:¿Que librería habría que bajar/comprar, la de CLIPPER o la de XBASE?
/*
obj.ChrCount( Chr, Str )
obj A FUNCky Object created by a previous call to CreateObject.
Chr A string containing the character to search for.
Str A string to search.
Returns The number of times Chr appears within Str. If Chr is not found to be in Str, 0 is returned.
*/
function main()
oFuncky:=CreateObject("FUNCky")
msginfo(oFuncky:ChrCount("t","Esto es un test")) // Visualiza un 3 (el número "t")
msginfo(oFuncky:ChrCount("A", "1234567")) // Visualiza 0 (no hay ninguna "A")
return nil
/*
obj.Ping( Server [, Format ] [, Timeout ] )
obj A FUNCky Object created by a previous call to CreateObject.
Server The name or IP address of the server to ping.
Format A format string used to define the output. Optional, the default is "Reply from: xxx.xxx.xxx.xxx RTT: xx TTL: xx.
Timeout The number of milliseconds to wait before giving up. Optional. The default is 20 seconds.
Returns A string containing the ping results or "" if the ping timed out or the server was not found.
*/
msginfo(oFuncky:Ping("www.microsoft.com","",10000)) // Visualiza la IP del sitio.
No, es de pago.antolin wrote:¿Es FREEWARE?
antolin wrote:...he instalado la demo pero no se ni donde estan las librerías...
Return to FiveWin para Harbour/xHarbour
Users browsing this forum: No registered users and 11 guests