all tasks

This commit is contained in:
Ingy döt Net 2013-04-11 01:07:29 -07:00
parent b83f433714
commit 68f8f3e56b
14735 changed files with 178959 additions and 0 deletions

View file

@ -0,0 +1,24 @@
public class Trims{
public static String ltrim(String s){
int i = 0;
while (i < s.length() && Character.isWhitespace(s.charAt(i))){
i++;
}
return s.substring(i);
}
public static String rtrim(String s){
int i = s.length() - 1;
while (i > 0 && Character.isWhitespace(s.charAt(i))){
i--;
}
return s.substring(0, i + 1);
}
public static void main(String[] args){
String s = " \t \r \n String with spaces \t \r \n ";
System.out.println(ltrim(s));
System.out.println(rtrim(s));
System.out.println(s.trim()); //trims both ends
}
}