Skip to content

Instantly share code, notes, and snippets.

@jaehoo
Last active August 29, 2015 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaehoo/8725708 to your computer and use it in GitHub Desktop.
Save jaehoo/8725708 to your computer and use it in GitHub Desktop.
package com.oz.test;
import junit.framework.TestCase;
import org.junit.Test;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Created with IntelliJ IDEA.
* User: asanchez
* Date: 30/01/14
* Time: 09:57 AM
*
* @author <a href="jaehoo@gmail.com">Alberto Sánchez</a>
* Contact me by:
* <ul><li>Twitter: @jaehoox</li><ul>
*/
public class DummyTest extends TestCase{
@Test
public void testRemoveMinusSign() throws Exception {
String [] values= {"1000-", "200,00 -","30 00 - "," 500.00 - ","300 -","000- x -"};
for(String v :values){
System.out.println(removeMinus(v));
}
}
/**
* Replace minus sign and put at the begin of the String
* @param strValue
* @return move minus sign at the begin of the String, if not match return original String value
*/
public String removeMinus(String strValue){
String pattern="\\-\\s*$";
Pattern p= Pattern.compile(pattern);
Matcher m= p.matcher(strValue);
if(m.find()){
return "-"+m.replaceFirst(" ");
}else{
return strValue;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment