English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

example:
String var1 = "abcdef123456";
and
String var2 = "123456abcdef"

should return 123456 and abcdef respectively

var1 and var 2 are user input

2007-05-16 22:39:01 · 4 answers · asked by nick 1 in Computers & Internet Programming & Design

4 answers

String var3 = var1.substring(var1.length() - 6, var1.length())

That should work.
Documentation is below.

2007-05-16 22:50:20 · answer #1 · answered by AnalProgrammer 7 · 0 0

You can use the java string class to read the string.length(), then use the length() - 6 to read the string from there. Remember the string will start at a count of 0, then go to length() - 1 as it is 0 indexed.

2007-05-17 05:51:43 · answer #2 · answered by Anonymous · 0 0

get the total length of the string
them move back to lenghtOfString-6 then start reading character by character from current posotion to the end of string.

2007-05-17 06:36:21 · answer #3 · answered by Anonymous · 0 0

you can do this in lot of way..
i will give the logic

get the string and reverse it.and get the first 6 chars of that string then again reverse it.you will get the required answer.
: )

2007-05-17 08:48:29 · answer #4 · answered by M S B 2 · 0 0

fedest.com, questions and answers