You consistently do
String foo = new String("some string"). This is useless, as"some string"already is a string. Simplify your code toString foo = "...".You declare some variables far before you use them. Try to declare your variables as close to their point of use as possible, e.g. instead of
char ch; ... ch = str.charAt(2);you could just do
char ch = str.charAt(2). The same holds true forpos,value,value1,value2,value3.Actually, you don't even need the
chvariable as you could doswitch (str.charAt(2)) { ... }directly.Some of your variables have very bad named:
value1does not communicate any intent or meaning. Other variables use unecessary abbreviations.You have certain magic numbers that could be replaced. E.g. in
str.substring(pos + 4, pos + 4 + 6), the4is actuallymatchExpDtAI.length(). I have no idea where the6comes from.This code is pure obfuscation:
value = value.substring(pos + 5, value.length()); value1 = value.substring(0, 5); value2 = value.substring(value1.length(), value1.length() + 4); value3 = value.substring(value1.length() + value2.length(), value1.length() + value2.length() + 1); value3 = value1 + "-" + value2 + "-" + value3; value = value.trim(); System.out.println("Found string Item : " + value3);Note that you don't use the
value1,value2, andvalue3variables outside of this snippet, so they are unecessary. If we count the lengths of those substrings, we can see that this code should be equivalent:value = value.substring(pos + 5), value.length()); System.out.println("Found string Item : " + value.substring(0, 5 ) + "-" + value.substring(5, 5 + 4 ) + "-" + value.substring(5 + 4, 5 + 4 + 1)); value = value.trim();Those constant offsets can be folded, which makes it easier to see that these substrings are actually consecutive:
value = value.substring(pos + 5), value.length()); System.out.println("Found string Item : " + value.substring(0, 5) + "-" + value.substring(5, 9) + "-" + value.substring(9, 10)); value = value.trim();Actually, let's use
String.formatfor that:value = value.substring(pos + 5), value.length()); System.out.println(String.format("Found string Item: %s-%s-%s", value.substring(0, 5), value.substring(5, 9), value.substring(9, 10) )); value = value.trim();
You consistently do
String foo = new String("some string"). This is useless, as"some string"already is a string. Simplify your code toString foo = "...".You declare some variables far before you use them. Try to declare your variables as close to their point of use as possible, e.g. instead of
char ch; ... ch = str.charAt(2);you could just do
char ch = str.charAt(2). The same holds true forpos,value,value1,value2,value3.Actually, you don't even need the
chvariable as you could doswitch (str.charAt(2)) { ... }directly.Some of your variables have very bad named:
value1does not communicate any intent or meaning. Other variables use unecessary abbreviations.You have certain magic numbers that could be replaced. E.g. in
str.substring(pos + 4, pos + 4 + 6), the4is actuallymatchExpDtAI.length(). I have no idea where the6comes from.This code is pure obfuscation:
value = value.substring(pos + 5, value.length()); value1 = value.substring(0, 5); value2 = value.substring(value1.length(), value1.length() + 4); value3 = value.substring(value1.length() + value2.length(), value1.length() + value2.length() + 1); value3 = value1 + "-" + value2 + "-" + value3; value = value.trim(); System.out.println("Found string Item : " + value3);Note that you don't use the
value1,value2, andvalue3variables outside of this snippet, so they are unecessary. If we count the lengths of those substrings, we can see that this code should be equivalent:value = value.substring(pos + 5), value.length()); System.out.println("Found string Item : " + value.substring(0, 5 ) + "-" + value.substring(5, 5 + 4 ) + "-" + value.substring(5 + 4, 5 + 4 + 1)); value = value.trim();Those constant offsets can be folded, which makes it easier to see that these substrings are actually consecutive:
value = value.substring(pos + 5), value.length()); System.out.println("Found string Item : " + value.substring(0, 5) + "-" + value.substring(5, 9) + "-" + value.substring(9, 10)); value = value.trim();Actually, let's use
String.formatfor that:value = value.substring(pos + 5), value.length()); System.out.println(String.format("Found string Item: %s-%s-%s", value.substring(0, 5), value.substring(5, 9), value.substring(9, 10) )); value = value.trim();
You consistently do
String foo = new String("some string"). This is useless, as"some string"already is a string. Simplify your code toString foo = "...".You declare some variables far before you use them. Try to declare your variables as close to their point of use as possible, e.g. instead of
char ch; ... ch = str.charAt(2);you could just do
char ch = str.charAt(2). The same holds true forpos,value,value1,value2,value3.Actually, you don't even need the
chvariable as you could doswitch (str.charAt(2)) { ... }directly.Some of your variables have very bad named:
value1does not communicate any intent or meaning. Other variables use unecessary abbreviations.You have certain magic numbers that could be replaced. E.g. in
str.substring(pos + 4, pos + 4 + 6), the4is actuallymatchExpDtAI.length(). I have no idea where the6comes from.This code is pure obfuscation:
value = value.substring(pos + 5, value.length()); value1 = value.substring(0, 5); value2 = value.substring(value1.length(), value1.length() + 4); value3 = value.substring(value1.length() + value2.length(), value1.length() + value2.length() + 1); value3 = value1 + "-" + value2 + "-" + value3; value = value.trim(); System.out.println("Found string Item : " + value3);Note that you don't use the
value1,value2, andvalue3variables outside of this snippet, so they are unecessary. If we count the lengths of those substrings, we can see that this code should be equivalent:value = value.substring(pos + 5, value.length()); System.out.println("Found string Item : " + value.substring(0, 5 ) + "-" + value.substring(5, 5 + 4 ) + "-" + value.substring(5 + 4, 5 + 4 + 1)); value = value.trim();Those constant offsets can be folded, which makes it easier to see that these substrings are actually consecutive:
value = value.substring(pos + 5), value.length()); System.out.println("Found string Item : " + value.substring(0, 5) + "-" + value.substring(5, 9) + "-" + value.substring(9, 10)); value = value.trim();Actually, let's use
String.formatfor that:value = value.substring(pos + 5, value.length()); System.out.println(String.format("Found string Item: %s-%s-%s", value.substring(0, 5), value.substring(5, 9), value.substring(9, 10) )); value = value.trim();
You consistently do
String foo = new String("some string"). This is useless, as"some string"already is a string. Simplify your code toString foo = "...".You declare some variables far before you use them. Try to declare your variables as close to their point of use as possible, e.g. instead of
char ch; ... ch = str.charAt(2);you could just do
char ch = str.charAt(2). The same holds true forpos,value,value1,value2,value3.Actually, you don't even need the
chvariable as you could doswitch (str.charAt(2)) { ... }directly.Some of your variables have very bad named:
value1does not communicate any intent or meaning. Other variables use unecessary abbreviations.You have certain magic numbers that could be replaced. E.g. in
str.substring(pos + 4, pos + 4 + 6), the4is actuallymatchExpDtAI.length(). I have no idea where the6comes from.This code is pure obfuscation:
value = value.substring(pos + 5, value.length()); value1 = value.substring(0, 5); value2 = value.substring(value1.length(), value1.length() + 4); value3 = value.substring(value1.length() + value2.length(), value1.length() + value2.length() + 1); value3 = value1 + "-" + value2 + "-" + value3; value = value.trim(); System.out.println("Found string Item : " + value3);Note that you don't use the
value1,value2, andvalue3variables outside of this snippet, so they are unecessary. If we count the lengths of those substrings, we can see that this code should be equivalent:value = value.substring(pos + 5), value.length()); System.out.println("Found string Item : " + value.substring(0, 5 ) + "-" + value.substring(5, 5 + 4 ) + "-" + value.substring(5 + 4, 5 + 4 + 1)); value = value.trim();Those constant offsets can be folded, which makes it easier to see that these substrings are actually consecutive:
value = value.substring(pos + 5), value.length()); System.out.println("Found string Item : " + value.substring(0, 5) + "-" + value.substring(5, 9) + "-" + value.substring(9, 10)); value = value.trim();Actually, let's use
String.formatfor that:value = value.substring(pos + 5), value.length()); System.out.println(String.format("Found string Item: %s-%s-%s", value.substring(0, 5), value.substring(5, 9), value.substring(9, 10) )); value = value.trim();
Before thinking about whether an object-oriented approach would be sensible (it isn't), you have other parts of your code to clean up first.