Help Strings

Discussion in 'Spigot Plugin Development' started by jay275475, Mar 16, 2015.

  1. I need to know if its possible to get a word inside a string, then a number after it. Like this.
    String E = "Hello = 0 Hello2 = 1";
    How would I get int for Hello2?
     
  2. What well that do?
     
  3. Nvm I mean how well i get the int?
     
  4. Inkzzz

    Resource Staff

    .split("=", "=");
     
  5. I would split 'Hello' and 'Hello2' so it's easier to get the value. Like this:

    Code (Text):
            String e = "Hello=0;Hello2=1";
         
            String[] toArray = e.split(";");
            String theValueYouWant = "";
         
            for(String s : toArray)
                if(s.startsWith("Hello2")) {
                 
                    theValueYouWant = s.split("=")[1];
                 
                 
                }
     
    • Agree Agree x 1
  6. Thx, I'm coding a Twitch Status plugin and I wanted to add the viewer amount!
     
  7. Its not even working. :(
     
  8. Is it open source? I would be interested in it.

    If yes: pm me ^^
    If no: ok for me ^^
     
  9. Its not open source yet atleast but I've got it working, I just need to figure out how to add viewer count
     
  10. How do i get something like this?
    blah blah 244455 blah blah >viewers 1<
     
  11. If you would tell me how the actual return string is, I could help you
     
  12. I get IOEceptions
     
  13. Here,
    PHP:
    ,"game":"Wizard101","viewers":0,
    This is what it returns.

    PHP:
    String[] toArray = e.split(",");
                        String viewers = "";
                   
                        for(String s : toArray)
                            if(s.startsWith("'viewers'")) {
                           
                                viewers = s.split(":")[1];
                             
    This isn't working.
     
  14. ...Are you trying to manually parse JSON?
     
    • Agree Agree x 2
    • Funny Funny x 1
  15. Yes, he does.
     
  16. Let me rephrase:

     
  17. Oh, then what do I do?
     
  18. Well you you haven't noticed I'm trying to read a BUFFEREDREADER on a website.
     
  19. Use any of the various JSON libraries that already exist, and then have them parse it for you. Bukkit has json-simple already loaded if I'm not mistaken.

    That makes no difference in what you're parsing, only where from. A JSON library will handle it fine :)