Hi!
Lets say i have this expression I10I20I-3++ which should give me 27. I just cant seem to find a way of removing those I's or if it is any other letter from the string.
Not forgetting i have to then evaluate the expression.
I tried using regex but no luck...

public static String removeIs(String input)
    {
        //String check = input.replaceAll("[^/+/-/*//^0-9/-]+", " ");
        String check = input.replaceAll("[^-+*/^0-9/-](?![^(]*\\))"," ");
        return check;
    }
//The posiblities that either you have been used deprecated methods or you didn't have catched your exceptions during stream reading from console.
//So here is the example that might give you some sort of help.
import java.io.*;
public class abcd
{

    public  String removeIs(String input)
        {

            //String check = input.replaceAll("[^/+/-/*//^0-9/-]+", " ");
            String check = input.replaceAll("[^-+*/^0-9/-](?![^(]*\\))"," ");
            return check;
        }
    public void showString()// throws IOException .I didn't use it here because sometimes in the code this might be situations that we will get 
    //unchecked exception and the program will failed to compile . And IOException as you might be aware of throws only checked exceptions.
    {
        try
        {
        BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
            String a=in.readLine();
            String b=removeIs(a);
            System.out.println(b);
    }
    catch(Exception e)
    {}
    }

public static void main(String []argd)
{
    abcd ad= new abcd();
    ad.showString();
}
}

basically the same remarks as in the other thread, but here I 'll add just a fourth one:
-- repeated --
1. showing off doesn't make you the better programmer
2. follow Java naming conventions
3. don't hand out code, all they'll learn is how to copy paste
-- new one --
4. don't ever, EVER do this:

catch(Exception e)
    {}

first of all, you should go as specific you can with catching exceptions, but even if you don't, don't hide the exception. in the above code, how will you ever know an exception occured?

This article has been dead for over six months. Start a new discussion instead.