-
fast way to split string?
fast way to split string?
I know there are a lot of threads about this subject, but i still need some help. i'm making a calender. all the data is in a text file as folllows:
&data=10/11/2002=event on this day|11/12/2002=event on this day|15/12/2002=event on this day|...&.
now i now how to split all the data and put it into arrays, but this goes to slow. i've seen some scripts around here wich bypass the string.split() that i use, but i can't figure out how to use them for my case. can some help me with a bit of explination.... thx P-Sch1FT
I think...I dreamed...in pixels last night...
-
Hi,
there is a prototype function mysplit like that:
put code into first frame
Code:
String.prototype.mysplit = function (ch) {
var k, s, l = this.length;var res = new Array();
for (k=s=1; k<=l; k++) {
if (substring(this, k, 1) == ch)
{res.push(substring(this, s, k-s));s = k+1;}
}
if (s<=l) {res.push(substring(this, s, l-s+1));}
return res;
}
Now, shwerever you want to split something, use xy.mysplit(',') instead of xy.split(',')
Musicman
-
is that it? thx a lot i'll give it a go as soon as i can go home from this lazy job.
P-Sch1FT
I think...I dreamed...in pixels last night...
-
it won't work. i tried several things but i don't understand the String.prototype.mysplit = function (ch) line. my text file looks like this.
&DATA=20/11/2002=event on this day|21/11/2002=event on this day|26/12/2002=event on this day|......&loaded=ok
i want to split data first at the | sign, after this it should again split at the = sign. now I guess the (ch) in the first line represents a ',' yes? no?
help wanted.......
P-Sch1FT
I think...I dreamed...in pixels last night...
-
Hi,
this should just be a something.mysplit('|') for the main split and somethingelse.mysplit('=') for the sub splits
Musicman
-
hi,
i don't know why but it doesn't split. if i put a trace(this) on the first line the result gives me the whole string AND the first character of this string (i.e. result= This is the whole string AND T)
this is because the first split doesn't work, i can't figure out why, but if i put a trace in the first FOR loop, no trace happens, so i guess it never loops. ??? even more
watching the code now, i might know why, the 1 and l looks pretty much the same, i probably made a mistake somewhere
P-Sch1FT (struggling and learning)
thx
I think...I dreamed...in pixels last night...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|