| split() method 
 
	 
	
		| Author | Message |   
		| Martin 
 
  
 
 
 | 
			
				|  Posted: Sun Dec 25, 2005 7:18 pm    Post subject: split() method |  |   
				| 
 |  
				| 	  | code: |  	  | 
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?
 |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| Sponsor Sponsor
 
  
   |  |   
		|  |   
		| wtd 
 
 
 
 
 | 
			
				|  Posted: Sun Dec 25, 2005 7:37 pm    Post subject: (No subject) |  |   
				| 
 |  
				| 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 
 
  
 
 
 | 
			
				|  Posted: Sun Dec 25, 2005 8:23 pm    Post subject: (No subject) |  |   
				| 
 |  
				| Hey, good idea! 
 Thanks a ton
  |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| Martin 
 
  
 
 
 | 
			
				|  Posted: Mon Dec 26, 2005 2:39 am    Post subject: (No subject) |  |   
				| 
 |  
				| Apparently if you call the split method with somestring.split(regex, some_negative_number) it goes to the end of the string. |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| MysticVegeta 
 
  
 
 
 | 
			
				|  Posted: Thu Dec 29, 2005 12:23 am    Post subject: Re: split() method |  |   
				| 
 |  
				| Martin wrote: 	  | code: |  	  | 
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]
 |  
				|  |  |   
		|  |  |  
	  
		|  |   
		|  |  
 |