Android Utililty Methods String End of Line Convert

List of utility methods to do String End of Line Convert

Description

The list of methods to do String End of Line Convert are organized into topic(s).

Method

StringconvertEOLToLF(String input)
Converts any instances of "\r" or "\r\n" style EOLs into "\n" (Line Feed).
StringBuilder res = new StringBuilder(input.length());
char[] s = input.toCharArray();
int from = 0;
final int end = s.length;
for (int i = 0; i < end; i++) {
    if (s[i] == '\r') {
        res.append(s, from, i - from);
        res.append('\n');
...
StringrmvEnter(String input)
rmv Enter
return input.replaceAll("\n", "");
StringremoveEnd(String str, String remove)

Removes a substring only if it is at the end of a source string, otherwise returns the source string.

A null source string will return null .

if (isEmpty(str) || isEmpty(remove)) {
    return str;
if (str.endsWith(remove)) {
    return str.substring(0, str.length() - remove.length());
return str;
StringnewLineToBr(String s)
new Line To Br
if (s == null)
    return null;
return replace(s, "\n", "<br>");
StringfilterEnter(String str)
filter Enter
int ind;
StringBuffer sb = new StringBuffer();
while ((ind = str.lastIndexOf("\n")) != -1) {
    sb.append(str.substring(0, ind));
    sb.append("\\n");
    sb.append(str.substring(ind + 1));
    str = sb.toString();
    sb.delete(0, str.length());
...
Stringfold(String recipients)
Builds a list of the recipients email addresses each on a different line, starting just from the second line with an HT ("\t") separator at the head of the line.
String[] list = StringUtil.split(recipients, ",");
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < list.length; i++) {
    String address = list[i] + (i != list.length - 1 ? "," : "");
    buffer.append(i == 0 ? address + CRLF : HT + address + CRLF);
return buffer.toString();
intfindEmptyLine(String s)
Find two consecutive newlines in a string.
int ret = 0;
while ((ret = s.indexOf("\n", ret)) != -1) {
    while (s.charAt(ret) == '\r') {
        ret++;
    if (s.charAt(ret) == '\n') {
        ret++;
        break;
...
StringdeleteEmptyLine(String str)
delete Empty Line
String dest = str;
if (str != null) {
    Pattern p = Pattern.compile("\r|\n");
    Matcher m = p.matcher(str);
    dest = m.replaceAll("");
return dest;
booleanisS(char ch)
Return true if chacters is S as defined in XML 1.0 S ::= (#x20 | #x9 | #xD | #xA)+
return (ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t');