Mandy Crow said:
i thought there is a specific vfp command for extracting from string
GETWORDNUM is exactlya that, it is a function that gets a word from a string, so it extracts part of a string from a longer string. Usually it splits by spaces, as that's the normal dellimiter of words, but it has athe paramater to choose splitting by other characters, not only comma.
I also don't get why you tried MEMLINES. That splits lines. If you only have a single line, you don't need MEMLINES.
There is a command for extracting somethng from a string, you just have to combine those words in the right order and abbreaviation, it's STREXTRACT, shortened from STRINGEXTRACT, so you see a lot of functions shorten STRING TO STR, likje FILTOSTR, STREXTRACT or also the STR() function, it's a common abbreviation used for strings in the naming of functions.
STREXTRACTs use case differs from what you want to do, though. You would use that if you know a delimiter before the part to extract from a string and a delimiter after what you want to extract, called the BeginDelimiter and EndDelimiter, for the case "part1,part2" the comma is the end delimiter for part1, but part1 has no begin delimiter. For part2 the comma is the begin delimiter, but it has no end delimiter. So just because it is a function to extract a part of a string, it's not very useful for this case and just because it's a function extracting a string it's not usable for all times you want a part of a string.
There are three more string functions that extract from a string, LEFT, RIGHT and SUBSTR. Are they appropriate for the case of "part1,part2"? LEFT could get the left part, RIGHT could get the right part. Why don't we use them for this and use GETWORDNUM for this exact case, Mandy? That's a homework question. The hint to solving that is: Look at the definitions of the functions and what parameters they have and how useful they are for the case you want to solve. For the general case of a string with two parts separated by a comma, the position of the comma isn't fixed, because part1 and part2 can have any length. Another hint is: You could find out the position and then make use of LEFT and RIGHT or LEFT and SUBSTR. But that's overcomplicating things, as we haqve the GETWORDNUM function at hand, which - look up the definition and parameter description - gives us the straight forward set of parameters to split at a comma, no matter where exactly it is, so it's the best to use that.
How do we get there and know what to use? Experience and knowledge. You can't program, if you need to lookup something every 5 seconds, so you have to know your string functions like you know your abc and multiplication tables. What you have to do is learn more about the plethora of functions and commands and don't guess what#s perhaps working, know what's right for the case at hand.
MEMLINES would become useful again, if your editbox would contain many lines of "lastname, firstname" sequences, likewise ALINES could be used, though. And if such data is in a file thats a use case not for FILETOSTR followed by ALINES and GETWORNUM, it's a case for APPEND FROM filename TYPE CSV, because that does all that in one command. And while that's so compact in comparison of the need of using ALINES an da loop of GETWORNUM, it's not the best idea to create a file from a string to be able to use APPEND. Because creating files is using a slow medium of a hard drive, in comparison to doing things in RAM memory. So just because you already would know STREXTRACT or APPEND you don't use it for any string extraction or splitting, you use something that's appropriate for the current case.
And I want to conclude in giving the last advice about that: If you simply your problem case too much, i.e. ask how to split "Crow,Mandy" when the problem at hand would be splitting a list of names. You only get a good solution provided you give a good explanation of the problem. And that also works for yourself in making you aware of what could be a solution. Think MEMLINES with LINES in it when you have one line? Think again, Mandy.
Chriss