case statement
Hi all,
I am trying to convert a C program to java, In the process i encounter a doubt. Somebody help me out in fixing this.
char ch;
switch (ch)
{
case 32:
printf ("space encountered\n");
break;
case '\n'
printf ("new line char encountered\n");
break;
case 33 ... 126:
printf ("alphabets / numbers / special chars encountered\n");
}
This is the part of C program where i am struggling to convert. The statement "CASE 33 ... 126" will select all the ascii char between the range 33 to 126. How can i use the same sort of case selection in java.
Please help me out. Thanks in advance.
This case statement selects all alphabets in both caps and non caps, numbers, all types of braces, all operators and special characters written over the numbers. In C i was using this to count the nuber of valid characters without space. I want to do the same thing in java.
> This case statement selects all alphabets in both
> caps and non caps, numbers, all types of braces, all
> operators and special characters written over the
> numbers. In C i was using this to count the nuber of
> valid characters without space. I want to do the same
> thing in java.
Is performance important?
You can use regexp to solve the problem.
Kaj
char ch;
switch (ch) {
case 32:
System.out.println("space encountered\n");
break;
case '\n'
System.out.println("new line char encountered\n");
break;
case 33:
case 34:
.......
case 125:
case 126:
System.out.println("alphabets / numbers / special chars encountered\n");
break;
default:
//something else
}
Edit: Not necessarily pretty, but it is what you wanted.