0

I'm developing a Jframe using the GUI designing tool in NetBeans, as part of my school project.

Say the user inputs "ABCDEFG123456" and presses a button. The program should store characters in the range from 2 to 5 of that string in variable1 and from 7 to the end of the string in variable2.

And the result should be: variable1 = "BCDE" variable2 = "G123456"

Update:

enter image description here

Variables:
1st textarea = ep
rearrange = exe
2nd textarea = output
7
  • 2
    Can we see some code. Do not be afraid to show us what you have done. :) Commented Nov 20, 2015 at 14:39
  • Very willing to help but as gonzo said please add some code :) would feel better and not writing for you! Hint Hint, look at tutorialspoint.com/java/java_string_substring.htm Commented Nov 20, 2015 at 14:40
  • 2
    Use String#substring. Good luck. Commented Nov 20, 2015 at 14:41
  • I have not written anything, just designed the interface. I just want to know the mechanism to start coding. :) Commented Nov 20, 2015 at 14:42
  • @Skylight well lets see your interface. :) Commented Nov 20, 2015 at 14:43

1 Answer 1

1

If I understood correctly, your best bet is substring

       public static void main(String args[]){

          String userInput = new String("ABCDEFG123456");

          String variable1 = userInput.substring(1,5);
          String variable2 = userInput.substring(6, userInput.length());

          System.out.println(variable1);
          System.out.println(variable2);

       }

(haven't tested, maybe the indexes are wrong :-) )

Sign up to request clarification or add additional context in comments.

1 Comment

Yes! substring is what I'm looking for. Thanks a lot brother :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.