Howard Bullock
(KiX Supporter)
2005-10-17 11:19 PM
[edit] SPLIT [/edit] enhancement

Split($string,"") or even SPLIT($string) should return an array of single characters. This was suggested previously and rejected. Can it be reconsidered?

ShawnAdministrator
(KiX Supporter)
2005-10-17 11:38 PM
Re: SPILT enhancement

I give this a huge big thumbs-up second as well Howard.

LonkeroAdministrator
(KiX Master Guru)
2005-10-18 12:08 AM
Re: SPILT enhancement

I don't wanna mess with SPLIT or even the suggested SPILT.

I think better (cleaner) is to have a separate function for this.
say, Explode()

why cleaner? because the current behaviour is:
a) already there, been there for quite a while and some scripts rely on it
b) would bring inconsistency. couldn't no more just split with stuff but would need to check for the splitter string to avoid data corruption

not so good explanations but... I like the idea of the new feature but don't wanna see it in split.


kholm
(Korg Regular)
2005-10-18 12:11 AM
Re: SPILT enhancement

Howard

This one is impossible: SPLIT($string)
Because default split character is allready space, so it cannot be used because of backwords compatibility

This one Split($string,"")
Might be the solution, if Ruud wil make the change

It could be a great tool to find the first different char when comparing two strings

I see that Shawn wishes for this functionality too,
I suspect You both for for this wish to make an easy translates from other programming languages

I'll allso vote for this even if an UDF to split a string into an array of chars only needs about 5 lines.

-Erik


Radimus
(KiX Supporter)
2005-10-18 12:15 AM
Re: SPILT enhancement

Something like?

$array = Chars(string)


ShawnAdministrator
(KiX Supporter)
2005-10-18 12:21 AM
Re: SPILT enhancement

Erik (et al) is right - this prolly would cause issues - was reading the docs on the delim param:

Delimiter

Optional. String character(s) used to identify substring limits. If omitted, the space character (" ") is assumed to be the delimiter. If delimiter is a zero-length string, a single-element array containing the entire expression string is returned.

Wonder what that rational was behind that last design choice (to return the entire string instead of an array of chars) ... prolly a useful purpose in that too.


Sealeopard
(KiX Master)
2005-10-18 04:17 AM
Re: SPILT enhancement

Very quick way to turn a sring into an array as part of other functions. Though, the same could already be achieved via REDIM PRESERVE just not embedded in other functions.
Code:

$a='aaa'
$a=split($a)

$b='bbb'
redim preserve $b[0]



kholm
(Korg Regular)
2005-10-19 12:34 AM
Re: SPILT enhancement

Shawn

I have to wonder like You:

Quote:

Optional. String character(s) used to identify substring limits. If omitted, the space character (" ") is assumed to be the delimiter. If delimiter is a zero-length string, a single-element array containing the entire expression string is returned.

Wonder what that rational was behind that last design choice (to return the entire string instead of an array of chars) ... prolly a useful purpose in that too.





Why send a string to a function and return the same string??

I belive this is easy to implement for Ruud, that's why i'm woting for it.

It could be done in two ways:

    - Split($string,"") ; Second parameter is an empty string 0-length
    - Split($string,0) ; Second parameter mening no split char


In my oppinion we should not invent a new function to do this!

-Erik

ps.
KiXtart functions behaves exactly like vb-functions, just a litle better (smaller code), why not stay ahead

I hope the suggestion is not spilt


LonkeroAdministrator
(KiX Master Guru)
2005-10-19 06:36 AM
Re: SPILT enhancement

Quote:

Why send a string to a function and return the same string??




well, the return value is NOT the same string.
it's an array.

and, I know it would be nice to have this feature but hey, lets not break the current behaviour and scripts just because we don't want to learn new keyword.

also, having:
split(string, number)
won't work as kixtart uses type magic.
that is, kix automatically translates types, so when it should think 0 is intended to be a delimiter and when an option?

again.
I'm not against the functionality but don't wanna be blinded by new tech and trash the backwards compatibility.


maciep
(Korg Regular)
2005-10-19 02:51 PM
Re: SPILT enhancement

I agree, i don't want to break the current functionality. Not to mention there are times that i'd like to split a string and get a one-element array out of it - it can be very useful when you don't know what your input looks like.

But another function like Chars() would be nice.