Copy part of a String

Hello guys,

It can copy part of a String, (from a certain position)? I am unable to copy the second part (after the stroke) ... What could be wrong?

String str = "1234-5678";
String sub1 = str.substring(0,4);
String sub2 = str.substring(4,4);
println("Str/Sub: " + str + " - " + sub1 + " - " + sub2);

Thank you,

Answers

  • _vk_vk
    edited September 2015

    You are coping from index 4 to index 4 so... nothing

    String sub2 = str.substring(4,4);
    

    try

    String sub2 = str.substring(4,str.length());
    
  • Hello, thanks for the return,

    OK, it worked so yeah ...

    String posicoes = controller.getLabel().toString();
    String posBtnX  = posicoes.substring(0,4); 
    String posBtnY  = posicoes.substring(5,posicoes.length());
    println("Positions Buttons : " +posBtnX + "-" + posBtnY); 
    

    Thank you very very much,

  • Sorry the English, worked yes, it's OK ...

    Thank you

  • My pleasure :)

    The english is fine, sem problemas ;)

  • OK, thanks for the help... :)

Sign In or Register to comment.