cFlagString is a bit flag string created with gt_NewFlag()
nStart is the starting flag. This is an optional numeric value. If not supplied it defaults to 1.
nEnd is the ending flag. This is an optional numeric value. If not supplied it defaults to nStart.
Returns
The bit map string with the new flag settings.
Description
gt_ClrFlag() is used to turn flags within the flag string off.
Examples
LOCAL cFlags := gt_NewFlag( 20 ) // Create a bit flag string for 20
// logical values.
// Now, turn them all on.
? hb_StrToHex( cFlags := gt_SetFlag( cFlags, 1, 20 ) )
// Now set flags 10 to 15 to false.
? hb_StrToHex( cFlags := gt_ClrFlag( cFlags, 10, 15 ) )
// And set flag 18 to false.
? hb_StrToHex( cFlags := gt_ClrFlag( cFlags, 18 ) )
// And set flag 1 to false.
? hb_StrToHex( cFlags := gt_ClrFlag( cFlags ) )
cFlagString is a bit flag string created with gt_NewFlag()
nFlag is the flag to be tested.
Returns
A boolean value, TRUE if the flag is on, FALSE if it's off.
Description
gt_IsFlag() is used to test the state of a flag with a bit flag string.
Examples
// Print the setting of the flags in a flag string called <cDave>
LOCAL nFlag
FOR nFlag := 1 TO hb_BLen( cDave ) * 8
? "Flag number", nFlag, "==", gt_IsFlag( cDave, nFlag )
NEXT
nFlagCount is the number of flags you wish to store.
Returns
A string to hold the bit flags. All flags are set to FALSE.
Description
gt_NewFlag() is used to construct a bit flag string. The bit flag functions can be used for storing a large number of logical values in a small space.
To create a bit flag string you need to pass gt_NewFlag() a value that is equal to or greater than the number of flags required (you may want to allow for future expansion). Each character in the string returned from gt_NewFlag() will hold 8 logical values.
Examples
? hb_StrToHex( gt_NewFlag( 20 ) ) // Create a bit flag string for 20 logical values.
cFlagString is a bit flag string created with gt_NewFlag()
nStart is the starting flag. This is an optional numeric value. If not supplied it defaults to 1.
nEnd is the ending flag. This is an optional numeric value. If not supplied it defaults to nStart.
Returns
The bit map string with the new flag settings.
Description
gt_SetFlag() is used to turn flags within the flag string on.
Examples
LOCAL cFlags := gt_NewFlag( 20 ) // Create a bit flag string for 20
// logical values.
// Now set flags 10 to 15 to true.
? hb_StrToHex( cFlags := gt_SetFlag( cFlags, 10, 15 ) )
// And set flag 18 to true.
? hb_StrToHex( cFlags := gt_SetFlag( cFlags, 18 ) )
// And set flag 1 to true.
? hb_StrToHex( cFlags := gt_SetFlag( cFlags ) )
Return the ASCII value of a specified character in a string
Syntax
gt_AscPos( <cStr>, <nPos> ) β nAscVal
Arguments
cStr - The string
nPos - The position in cStr
Returns
nAscVal - The ASCII value of hb_BSubStr( <cStr>, <nPos>, 1 )
Description
Return the ASCII value of a specified character in a string Equivalent (but much faster) to
hb_BCode( hb_BSubStr( cStr, nPos, 1 ) )
NOTE:
invalid parameters will return -1 nPos > hb_BLen( cStr ) will return -2
This last behaviour is different to the Funcky function of the same name. I changed the behaviour because some of the strings I process contain embedded NULs.
Examples
? hb_BChar( gt_AscPos( "the cat sat on the mat", 3 ) ) // --> "e"
Return the position where two strings begin to differ
Syntax
gt_AtDiff( <cStr1>, <cStr2> ) β nPos
Arguments
cStr1 - A character string to compare
cStr2 - The string to compare with
Returns
nPos - The position in cStr2 where cStr1 begins to differ
Description
Return the position in cStr2 where cStr1 begins to differ. If the strings differ in the first character gt_AtDiff() will return 1. If the two strings are identical (or identical up to the last character in cStr2) the function will return 0.
NOTE:
invalid parameters will return -1
Examples
? gt_AtDiff( "the cat", "the rat" ) // --> 5
? gt_AtDiff( "the cat", "the " ) // --> 0
Find number of times a set of characters appears in a string
Syntax
gt_ChrTotal( <cChrs>, <cStr> ) β nTotOcc
Arguments
cChrs - The set of characters
cStr - The string to search
Returns
nTotOcc - The number of times the characters specified in
cChrs appears in cStr
Description
Returns the number of occurrences of characters belonging to the set cChrs in the string cStr. If no characters in cChrs appears in cStrgt_ChrTotal() will return 0.
NOTE:
invalid parameters will return -1
Examples
LOCAL cString := "the cat sat on the mat"
? gt_ChrTotal( "tae", cString ) // --> 10
? gt_ChrTotal( "zqw", cString ) // --> 0
Count the number of times a substring appears in a string
Syntax
gt_StrCount( <cChrs>, <cStr> ) β nFreq
Arguments
cChrs - The substring to find the frequency of
cStr - The string in which to find the character
Returns
nFreq - The number of times cChrs occurs in cStr
Description
gt_StrCount() counts how many times a specified substring appears in a string. If the substring does NOT appear in cStr this function will return 0. If the substring is a single character use gt_ChrCount() as it will be faster.
NOTE:
invalid parameters will return -1
Examples
? gt_StrCount( "the", "the cat sat on the mat" ) // --> 2
Return a string where it begins to differ from another
Syntax
gt_StrDiff( <cStr1>, <cStr2> ) β cRet
Arguments
cStr1 - A character string to compare
cStr2 - The string to compare with
Returns
cRet - A string beginning at the position in cStr2 where
cStr1 begins to differ from cStr1
Description
Return a string beginning at the position in cStr2 where cStr1 begins to differ from cStr1. If the two strings are identical (or identical up to the last character in cStr2) the function will return "".
NOTE:
invalid parameters will return ""
Examples
? gt_StrDiff( "the cat", "the rat" ) // --> "rat"
? gt_StrDiff( "the cat", "the " ) // --> ""