Last active
August 29, 2015 13:55
-
-
Save jaehoo/8725708 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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