hi all,

This is my first post in this site. I have a sentence like this

String input = "India/world is my Country and it is in Asia/in world";

I want to remove the word followed by the / and get the result of otheres.
Output
India is my Country and it is in Asia
I have tried using switch, by declaring in character. i would like to get the result without using the character. could any one help me?

If you post your code we can help you fix/improve it.

this is the code and the input is

**


    {abc}Ram/subject is/verb playing/object {def} and he will study {hij}**

I have removed the {} words inside this and i stored it in character. and get the result. Insted of moving it to character. I want to get the result using string. can you tell how to do that?

public class Extract {
            public static void main(String[] args) {
        try{


                // Open the file that is the first 
                // command line parameter
                FileInputStream fstream = new FileInputStream("singleInput.txt");
                // Get the object of DataInputStream
                DataInputStream in = new DataInputStream(fstream);
                BufferedReader br = new BufferedReader(new InputStreamReader(in));
                StringBuilder sb=new StringBuilder();
                String s;

                //Read File Line By Line
                while ((s = br.readLine()) != null)     
        {
                System.out.println("Tagged Sentence:"+s);           
        char[] ch = new char[500];
        String e = s.replaceAll("\\{.*?}","");
        System.out.print("Actual Sentence:");
            ch=e.toCharArray();
                        boolean flag=true, flag1=true;
            for(int i=0; i<e.length; i++) 
            {

                switch(ch[i]) {

                case '/': flag = false;

                break;

            case ' ': flag = true;

                break;

            }

                if(flag1)

                       System.out.print(e);
            }
        System.out.println("\n");

        }
        in.close();

                }catch (Exception e){//Catch exception if any
                    System.err.println("Error: " + e.getMessage());
                }
          }
        }

You could use String's indexOf method to find the next opening delimiter, then again to find the first closing delimiter after that, then use those two results in a call to String's substring method to extract the text between the delimiters

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.