Replace+n-th+word

A function to replace n-th word in a string with another string. Looks almost the same as the word$ function, but returns a modified string, rather than the word.

Parameters: replaceWord$(original_string$, n, delimiter$, replace_with$)

Let delimiter$ = " " to have a space as the word delimiter.

code format ="qbasic" string$ = "The quick brown fox jumps over the lazy dog." print "Function replaceWord:" print tab(5); "Replaces n-th word in a string with a" print tab(5); "string, using a user specified delimiter." print print "Example:" print tab(5); "String: "; string$ print print tab(5); "Replacing 2nd word..." print tab(5); replaceWord$(string$, 2, " ", "slow") print print tab(5); "Deleting 3rd word..." print tab(5); replaceWord$(string$, 3, " ", "") end

'********************************************************************************************* function replaceWord$(string$, wordNo, delimiter$, replaceWith$) i = 1 while word$(string$, i, delimiter$) <> "" if i = wordNo then if replaceWith$ <> "" then _ replaceWord$ = replaceWord$; delimiter$; replaceWith$ else replaceWord$ = replaceWord$; delimiter$; word$(string$,i,delimiter$) end if       i = i+1 wend replaceWord$ = mid$(replaceWord$,2) end function code