Solved 2 Strings with same Lenght.

Discussion in 'Spigot Plugin Development' started by JoseGamer_PT, May 29, 2016.

Thread Status:
Not open for further replies.
  1. HELLO SPIGOT COMMUNITY!

    So... I have 2 Strings:

    Code (Text):

    String label = "&7&l&m----------[&r &6" + str + " &7&l&m]----------";

    and

    String label2 = "&7&l&m";
     
    I want to get the lenght of "label, and for example is 8,
    i want to add 8 bars to label2

    Example:

    -ThisIsAnExample-
    (17 charactes)
    --------------------------
    (17 characters)

    I tried this:
    Code (Text):

    String label2 = "&7&l&m";
                int lenght = label.length();
                for (int i = 0; i < lenght; i++) {
                    label2 = label2 + "-";
                }
     
    But, this code show the second line more longer than the first
    Image:
    http://prntscr.com/b9wnz8

    THANKS FOR YOUR TIME!
    - JOSE
     
  2. Sabes o que quer dizer i++ ??
     
  3. Bump one every 24 hours... for your issue can't you just start 1 early/remove 1 after?
     
  4. Adiciona sempre um numero a int i?
     
  5. a guy with 4 resources... great work and amazing brain coming to spigot asking for help about java starting stuff.... i am sirsly... thats what happend to me after i got for 1 year and learned around more 6 languages....
    if you dont understand strings dude please go to Java Docs and learn the basic stuff of java
     
  6. I am in the javadocs right now c;
     
  7. great job then
     
  8. wtf
    Nada a ver.. É Percorrer o código .--.
    tu nem sabes o que estás a fazer XD
     
  9. SOLVED! THANKS FOR ALL HELP!

    :3

    No verao vou aprender melhor java. ;p
     
  10. Fdz nao é java !
    É pseudocódigo por amor de deus para de pedir código pensa e aprende os básicos antes de ires para o java !
    A comunidade PT já tem problemas por-causa de estarem sempre a pedir código ou pedir ajuda em coisas sem qualquer nexo ..
     
  11. Please keep the forums in English, as stated by the rules
     
  12. Oh, sorry i din't noticed that!
     
  13. You managed to fail basic addition, spelling and loop logic all at once, kind of impressive o_O

    Just add characters equal to the difference in the string length.

    Code (Java):
    int dif = string1.length() - string2.length();
    if(dif>0)
        while(--dif>-1)
            string2+="-";
     
     
    • Agree Agree x 1
Thread Status:
Not open for further replies.