Search code examples
stringvisual-foxpro

How to determine the end of string in VFP 9?


In some programming languages, such as C for example, the end of string may be marked as a separate null terminator symbol.

How do I determine if the current symbol is the end of string?

Currently I use some string functions' calls, but I guess it may be performed easier.

*the string's end
IF ISBLANK(SUBSTR(str, pos, 1) == .T.  AND CHR(32) != SUBSTR(str, pos,  1)
    RETURN .T.
ENDIF

Solution

  • VFP strings are not ASCIIZ strings as in C. A VFP string can contain any ASCII character including character 0 - chr(0)- which is a string termination character in C style languages. Normally the end of the string in VFP is the same as its length. But, although it is not clear from your question, sometimes you get a string from a C source (ie: a win32 call) where multiple string values are separated by chr(0) values. You can easily parse such a string into multiple string with a code like alines(). ie:

    ? ALines(laLines, "hello"+Chr(0)+"there",1+4,Chr(0)) && prints 2
    display memory like laLines && shows two string values
    

    Also you could use many string function like at(), occurs(), asc() ... to locate, count ... that character.