Detecting characters after symbols
I'm trying to write a method going in two ways - if a character after the symbol $ is an integer, then I want to go to the second if statement and execute it. If a character after the symbol $ is a digit (or a letter), then I want to set that number to 16, and every time a new digit is used, I want to increment the setNumber by 1. Here's what I tried:
for (i=0; i<anyLines.length; i++) {
int setNumber = 16;
// 1st IF statement
if (Character.isDigit(anyLines[i].charAt(the character after $)))
anyLines[i] = anyLines[i].replace("$","");
anyLines[i] = anyLines[i].replace(charAt(after zero),setNumber);
// Increment set number if a new digit is detected
}
else {
continue;
}
// 2nd IF statement
if (anyLines[i].isInteger(anyLines[i].charAt(the character after $))) {
anyLines[i] = anyLines[i].replace("$","");
any开发者_开发问答Lines[i] = Integer.toBinaryString(131072
+(Integer.parseInt(anyLines[i]))).substring(1,17);
}
else {
continue;
}
I have no idea how to do this.
Something like this:
public static void main(String[] args) {
String s = "af$Aklj$4r8$7jlkf$;a4$";
char[] cs = s.toCharArray();
for (int i = 0; i < cs.length; i++) {
if (cs[i] == '$') {
if (i + 1 < cs.length) {
i++;
if (Character.isDigit(cs[i])) {
System.out.print("digit after $: ");
} else if (Character.isLetter(cs[i])) {
System.out.print("letter after $: ");
} else {
System.out.print("unhandled character after $: ");
}
System.out.println(String.copyValueOf(cs, i-1, 2));
}
}
}
}
精彩评论