Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,11 @@
String removeLeading(String string, char[] characters) {
int index = 0;
for (char characterA : string.toCharArray()) {
for (char characterB : characters) {
if (characterA != characterB)
return string.substring(index);
}
index++;
}
return string;
}

View file

@ -0,0 +1,9 @@
String removeTrailing(String string, char[] characters) {
for (int index = string.length() - 1; index >= 0; index--) {
for (char character : characters) {
if (string.charAt(index) != character)
return string.substring(0, index + 1);
}
}
return string;
}

View file

@ -0,0 +1,28 @@
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 String trim(String s) {
return rtrim(ltrim(s));
}
public static void main(String[] args) {
String s = " \t \r \n String with spaces \u2009 \t \r \n ";
System.out.printf("[%s]\n", ltrim(s));
System.out.printf("[%s]\n", rtrim(s));
System.out.printf("[%s]\n", trim(s));
}
}

View file

@ -0,0 +1,19 @@
public static String ltrim(String s) {
int offset = 0;
while (offset < s.length()) {
int codePoint = s.codePointAt(offset);
if (!Character.isWhitespace(codePoint)) break;
offset += Character.charCount(codePoint);
}
return s.substring(offset);
}
public static String rtrim(String s) {
int offset = s.length();
while (offset > 0) {
int codePoint = s.codePointBefore(offset);
if (!Character.isWhitespace(codePoint)) break;
offset -= Character.charCount(codePoint);
}
return s.substring(0, offset);
}