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.

[682 byte] By [Mohamed_Thasneema] at [2007-11-27 10:03:02]
# 1
> 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.You can't
kajbja at 2007-7-13 0:37:57 > top of Java-index,Java Essentials,New To Java...
# 2
Is there any other way or function in achieving this
Mohamed_Thasneema at 2007-7-13 0:37:57 > top of Java-index,Java Essentials,New To Java...
# 3
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.
Mohamed_Thasneema at 2007-7-13 0:37:57 > top of Java-index,Java Essentials,New To Java...
# 4

> 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

kajbja at 2007-7-13 0:37:57 > top of Java-index,Java Essentials,New To Java...
# 5

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.

masijade.a at 2007-7-13 0:37:57 > top of Java-index,Java Essentials,New To Java...
# 6
Thankyou guys. i got it to work the way i wanted.
Mohamed_Thasneema at 2007-7-13 0:37:57 > top of Java-index,Java Essentials,New To Java...