#Java - Code Snippets for '#Trim' - 5 code snippet(s) found |
|
Sample 1. Trim New line and spaces in a string | |
|
String trimNewLineAndSpace(String str){
str = str.trim();
if(str.startsWith("\n")){
str = str.substring(1);
}
if(str.endsWith("\n")){
str = str.substring(0, str.length()-1);
}
return str;
}
|
|
Like Feedback string trim new lines string.substring string.startswith string.endswith |
|
|
Sample 2. Trim a String till first capital character. | |
|
String trimTillFirstCapitalCharacter(String str){
for(int i=0;i<str.length();i++){
if(str.charAt(i) != str.toLowerCase().charAt(i)){
return str.substring(i);
}
}
return str;
}
|
|
Like Feedback trim characters trim |
|
|
Sample 3. Trim square braces and spaces from a String | |
|
String trimSquareBracesAndSpaces(String str){
str = str.trim();
if(str.startsWith("[")){
str = str.substring(1);
}
if(str.endsWith("]")){
str = str.substring(0, str.length()-1);
}
return str;
}
|
|
Like Feedback string string trim trim |
|
|
Sample 4. Remove templatized arguments from a String | |
|
String removeTemplatizedArgument(String str){
String cleanStr = "";
boolean withinTemplatized=false;
int countBlock = 0;
for(char x: str.toCharArray()){
if(x == '<'){
withinTemplatized = true;
countBlock++;
continue;
} else if(x == '>'){
withinTemplatized = false;
countBlock--;
continue;
} else if(!withinTemplatized && countBlock == 0){
cleanStr = cleanStr + x;
}
}
return cleanStr;
}
|
|
Like Feedback string string trim trim char .toCharArray() |
|
|
|
Sample 5. Code Sample / Example / Snippet of org.apache.calcite.sql2rel.RelFieldTrimmer | |
|
public void assertConvertsTo(
String sql,
String plan,
boolean trim) {
String sql2 = getDiffRepos().expand("sql", sql);
RelNode rel = convertSqlToRel(sql2).project();
assertTrue(rel != null);
assertValid(rel);
if (trim) {
final RelBuilder relBuilder =
RelFactories.LOGICAL_BUILDER.create(rel.getCluster(), null);
final RelFieldTrimmer trimmer = createFieldTrimmer(relBuilder);
rel = trimmer.trim(rel);
assertTrue(rel != null);
assertValid(rel);
}
String actual = NL + RelOptUtil.toString(rel);
diffRepos.assertEquals("plan", plan, actual);
}
|
|
Like Feedback org.apache.calcite.sql2rel.RelFieldTrimmer |
|
|