Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
MegaFox 1002 (CalendarDemo form)
Message
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
00872703
Message ID:
00872713
Views:
37
I wonder if this is what I would need from thread id 820749 .
Don't know how to reference a message as a hyperlink.

*** The calling routine:

STORE "Marietta, GA 30066" TO my_string

*** Display word# 3 in the string which is "30066". ***
STORE 3 TO next_word
STORE GETWORD(my_string, next_word, " ") TO word_output
? next_word
? word_output
WAIT

RETURN
==================================================================


FUNCTION GETWORD
LPARAMETERS orig_str, desired_word_num, delimiter_char

LOCAL bypass, comparemv, current_word, start_point, stop_point, tempmv

STORE ALLTRIM(orig_str) TO orig_str

STORE "N" TO bypass

IF LEN(orig_str) = 0
STORE "Y" TO bypass
ENDIF
* Add the delimiter to the end of the original string so
* the last word can be gotten.
STORE orig_str + delimiter_char TO orig_str


STORE 1 TO start_point
STORE 0 TO current_word
STORE 1 TO countermv
STORE "" TO tempmv
STORE LEN(orig_str) + 1 TO stop_point

DO WHILE (current_word < desired_word_num) AND ;
countermv < stop_point AND bypass = "N" && DO WHILE #1

IF start_point > stop_point - 1
STORE stop_point - 1 TO start_point
ENDIF
STORE "" TO comparemv
STORE "" TO tempmv

*-------------------------------------------------------
* Get a word from the original string (orig_str).
SET EXACT ON
DO WHILE countermv < stop_point && DO WHILE #2
* This will loop until the counter gets up to the "stop_point"
* or an EXIT is reached.
* The "stop_point" is "one count past" the end of the string.
STORE SUBSTR(orig_str, countermv, 1) TO comparemv
IF comparemv = delimiter_char
* The "countermv - start_point" causes the delimiter not
* to be included in the output.
STORE SUBSTR(orig_str, start_point, countermv - start_point ) ;
TO tempmv
EXIT && <--- exit loop
ENDIF
STORE countermv + 1 TO countermv
ENDDO && DO WHILE #2
SET EXACT OFF
*-------------------------------------------------------

* Set the new start_point for the next word.
STORE countermv TO start_point

* Point to the next character (beyond the delimiter) in the string.
STORE countermv + 1 TO countermv

IF delimiter_char = tempmv
* There were two or more delimiters in a row.
* So, do not count the extra delimiter as a word.
ELSE
* Point to the next word in the string.
STORE current_word + 1 TO current_word
ENDIF

ENDDO && DO WHILE #1

* If the end of the Original String was reached before the
* "Desired Word Number", set the output word to Empty String.
IF current_word < desired_word_num
STORE "" TO tempmv
ELSE
* Remove leading and trailing spaces.
STORE ALLTRIM(tempmv) TO tempmv
ENDIF

RETURN tempmv
Previous
Reply
Map
View

Click here to load this message in the networking platform