Add whitespaces to a string

Put your problem here if it does not fit any of the other categories.

Add whitespaces to a string

Postby solo » Mon Nov 05, 2012 11:31 pm

Hi all,

I want to add whitespaces to a string whenever the following is discovered:
+ - * / ^

So if my string is:
Code: Select all
editTextInputData = "(1+2)*(3/4)-(5+6)";


It should be:
Code: Select all
editTextInputData = "( 1 + 2 ) * ( 3 / 4 ) - ( 5 + 6 )";


This is what i got :
Code: Select all
    /*- add Spaces To Equation ----------------------------------------- */
    public void addSpaces (){
      editTextInputDataTemp = editTextInputDataTemp.replaceAll("\\+", " + ");
      editTextInputDataTemp = editTextInputDataTemp.replaceAll("\\-", " - ");
      editTextInputDataTemp = editTextInputDataTemp.replaceAll("\\*", " * ");
      editTextInputDataTemp = editTextInputDataTemp.replaceAll("\\/", " / ");

      editTextInputDataTemp = editTextInputDataTemp.replaceAll("\\(", " ( ");
      editTextInputDataTemp = editTextInputDataTemp.replaceAll("\\)", " ) ");

    } 
~ Asking if computers can think is like asking if submarines can swim.
User avatar
solo
Junior Developer
Junior Developer
 
Posts: 22
Joined: Fri Mar 25, 2011 9:51 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google [Bot] and 15 guests