
-----------------------------------
Martin
Sun Dec 25, 2005 7:18 pm

split() method
-----------------------------------

String ts = ",,,asdf,asdf,,,asdf,,adsf,,fdsa,,,,,fdas,,fsda,,,fin,,,";
System.out.println ("test string = " + ts);
String[] tss = ts.split(",");
for (int i = 0; i < tss.length; ++i) {
    System.out.println (tss[i]);
}
System.out.println ("done");

Now, tss in this case is "", "", "", "asdf", ..., "fin" with the last three columns ignored. Does anyone know how I can get it to include these?

-----------------------------------
wtd
Sun Dec 25, 2005 7:37 pm


-----------------------------------
Brute force, but add a single character to the end, if the last character is a comma.  Then later just ignore the last String in the array.

-----------------------------------
Martin
Sun Dec 25, 2005 8:23 pm


-----------------------------------
Hey, good idea!

Thanks a ton :-)

-----------------------------------
Martin
Mon Dec 26, 2005 2:39 am


-----------------------------------
Apparently if you call the split method with somestring.split(regex, some_negative_number) it goes to the end of the string.

-----------------------------------
MysticVegeta
Thu Dec 29, 2005 12:23 am

Re: split() method
-----------------------------------

String ts = ",,,asdf,asdf,,,asdf,,adsf,,fdsa,,,,,fdas,,fsda,,,fin,,,";
System.out.println ("test string = " + ts);
String[] tss = ts.split(",");
for (int i = 0; i < tss.length; ++i) {
    System.out.println (tss[i]);
}
System.out.println ("done");

Now, tss in this case is "", "", "", "asdf", ..., "fin" with the last three columns ignored. Does anyone know how I can get it to include these?

um could you run a backwards loop and check for it then?

[syntax="Turing Pseudo *untested*"]
var endString : string
for decreasing x : length(ts)..1
if ts(x) not= "," then
endString := ts(x+1..*)
ts := ts(1..x)
exit
end if
end for
put stringSplit (ts, ",")+endString
[/syntax]
