Created
October 22, 2012 00:59
-
-
Save RobinStamer/3929144 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| private String strup(String s) { | |
| String strup = new String(s); | |
| if (strup.equals("")) { | |
| return ""; | |
| } | |
| while (new Character(strup.charAt(strup.length() - 1)).toString().matches("[`~!@#$%^&*_=|?/,. ]")) { | |
| try { | |
| strup = strup.substring(0, strup.length() - 1); | |
| if (strup.equals("")) { | |
| return ""; | |
| } | |
| } catch (Exception e) { | |
| return ""; | |
| } | |
| } | |
| Pattern test = Pattern.compile("^(.*?)[`~!@#$%^&*_=|?/,. ]*$"); | |
| System.out.println(strup + " vs " + s); | |
| Matcher m = test.matcher(s); | |
| try { | |
| System.out.println(m.groupCount()); | |
| System.out.println(m.group(0)); | |
| } catch (Exception e) { | |
| e.printStackTrace(); | |
| } | |
| try { | |
| System.out.println(m.group(1)); | |
| } catch (Exception e) { | |
| e.printStackTrace(); | |
| System.out.println(test); | |
| } | |
| return strup.trim(); | |
| } |
This file contains hidden or 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
| private String strup(String s) { | |
| String strup = new String(s); | |
| if (strup.equals("")) { | |
| return ""; | |
| } | |
| while (new Character(strup.charAt(strup.length() - 1)).toString().matches("[`~!@#$%^&*_=|?/,. ]")) { | |
| try { | |
| strup = strup.substring(0, strup.length() - 1); | |
| if (strup.equals("")) { | |
| return ""; | |
| } | |
| } catch (Exception e) { | |
| return ""; | |
| } | |
| } | |
| return strup.trim(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment