Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
explode() and implode()
#1
Create an explode and/or implode function in QBasic.

If you're familiar with php or a language like it, the explode function is exactly like the ones you see there.

Here's the php.net description:

Quote:explode

(PHP 3, PHP 4 )
explode -- Split a string by string
Description
array explode ( string separator, string string [, int limit])

Returns an array of strings, each of which is a substring of string formed by splitting it on boundaries formed by the string separator. If limit is set, the returned array will contain a maximum of limit elements with the last element containing the rest of string.

If separator is an empty string (""), explode() will return FALSE. If separator contains a value that is not contained in string, then explode() will return an array containing string.

I'm aware that QB can't return arrays from functions, so instead I want:

explode$ (string separator, string string, int part)

So the "part" variable specifies which part to return. Here's an example:

Code:
DIM explodedarray$(1 TO 3)

FOR I = 1 TO 3
  explodearray$(I) = explode$(" ", stringtoseparate$, I)
NEXT I

The function should return a null string if the part variable is not within the ranges of the parts in the string. so for a string like:

"hello world"

There would be 2 parts, and if explode$ was called with 3 or 0 for example, it would return "".

ALSO: To make this function seem useful, you should try to make another function, explodeparts%(string separator, string string), which returns the number of parts in the string.

Finally, make an implode function that joins an exploded array back together.

You'll get good marks if the explode$, explodeparts% and implode function are compatible, and work as expected.

Geez, that took ages to write Wink
Reply


Messages In This Thread
explode() and implode() - by oracle - 10-04-2003, 07:12 AM
explode() and implode() - by Ninkazu - 10-04-2003, 09:05 AM
explode() and implode() - by Blitz - 10-05-2003, 10:24 PM
explode() and implode() - by seph - 10-05-2003, 10:33 PM
explode() and implode() - by seph - 10-05-2003, 10:37 PM
explode() and implode() - by xhantt - 10-05-2003, 11:55 PM
explode() and implode() - by red_Marvin - 10-06-2003, 12:14 AM
explode() and implode() - by oracle - 10-06-2003, 04:02 AM
explode() and implode() - by SCM - 10-07-2003, 10:39 AM
explode() and implode() - by oracle - 10-07-2003, 10:44 AM
explode() and implode() - by red_Marvin - 10-07-2003, 12:20 PM
explode() and implode() - by toonski84 - 10-07-2003, 07:56 PM
explode() and implode() - by oracle - 10-08-2003, 12:53 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)