java - Splitting string into several different strings -


i getting source code site , putting code string, this:

501252,110,34496 331550,30,14114 403186,1,18 325033,31,15750 460287,14,2384 286659,11,1366 419439,1,67 678464,1,0 505044,1,70 522192,1,75 454391,1,0 504858,1,20 505396,1,40 469927,1,0 336670,2,155 392887,5,437 403568,1,0 488324,1,0 524031,1,0 429226,1,0 389668,1,0 383021,1,0 384599,1,0 363131,1,0 -1,-1 -1,-1 -1,-1 -1,-1 -1,-1 -1,-1 -1,-1 -1,-1 -1,-1 -1,-1 -1,-1 -1,-1 -1,-1 -1,-1 -1,-1   

i want split each number, , save them in there own strings, how go this?

current code: (if help?)

import java.awt.borderlayout; import java.awt.color; import java.awt.dimension; import java.awt.gridlayout; import java.awt.event.actionevent; import java.awt.event.actionlistener; import java.awt.event.keyevent; import java.io.bufferedreader; import java.io.ioexception; import java.io.inputstream; import java.io.inputstreamreader; import java.net.malformedurlexception; import java.net.url;  import javax.swing.jbutton; import javax.swing.jframe; import javax.swing.jpanel; import javax.swing.jtextfield;  public class dfgdfg {      static string username;     static jtextfield username = new jtextfield();     static string pooo;     static jpanel panel;     static jframe jframe;     static jbutton button;     static string line;       public static void main(string args[]) throws exception { gui();     }      public static void getsource() {         url url;         inputstream = null;         bufferedreader br;          try {             url = new url(                     "http://services.runescape.com/m=hiscore_oldschool/index_lite.ws?player="+username);             = url.openstream(); // throws ioexception             br = new bufferedreader(new inputstreamreader(is));              while ((line = br.readline()) != null) {                 system.out.println(line);             }         } catch (malformedurlexception mue) {             mue.printstacktrace();         } catch (ioexception ioe) {             ioe.printstacktrace();         } {             try {                 is.close();             } catch (ioexception ioe) {                 // nothing see here             }         }         }     public static void gui() {         jframe = new jframe("highscorelookup");         panel = new jpanel();         username = new jtextfield("enter username");         button = new jbutton("start");          jframe.setpreferredsize(new dimension(300, 300));         jframe.setdefaultcloseoperation(jframe.exit_on_close);         jframe.setvisible(true);         jframe.add(panel);          panel.add(username);         panel.add(button);         panel.setbackground(color.cyan);         button.setvisible(true);         username.setsize(100,50);         button.addactionlistener(new actionlistener() {              public void actionperformed(actionevent e)             {                 username = username.gettext().tostring();                 system.out.println(username);                 getsource();              }         });            jframe.pack();     }  } 

read each line file scanner, , use string.split(",") on each line. useful utility.

string.split break string 1d array using provided regex statement. here you'll breaking each line each comma.

edit:

based on comment still work you.

given input "501252,110,34496" output "501252", "110", "34496"

run code see mean:

public static void main(string[] args){     string input = "501252,110,34496";     string output = input.split(",");     string[] outputcontainsthis = new string[]{"501252", "110", "34496"}; } 

does suffice?


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -