Here you can find the source of getLineBreakOffsets(String replacementString)
public static List<Integer> getLineBreakOffsets(String replacementString)
//package com.java2s; /**//from w w w . j a v a2 s.c o m * Copyright (c) 2005-2012 by Appcelerator, Inc. All Rights Reserved. * Licensed under the terms of the Eclipse Public License (EPL). * Please see the license.txt included with this distribution for details. * Any modifications to this file must keep this entire header intact. */ import java.util.ArrayList; import java.util.List; public class Main { public static List<Integer> getLineBreakOffsets(String replacementString) { ArrayList<Integer> ret = new ArrayList<Integer>(); int lineBreaks = 0; int ignoreNextNAt = -1; //we may have line breaks with \r\n, or only \n or \r for (int i = 0; i < replacementString.length(); i++) { char c = replacementString.charAt(i); if (c == '\r') { lineBreaks++; ret.add(i); ignoreNextNAt = i + 1; } else if (c == '\n') { if (ignoreNextNAt != i) { ret.add(i); lineBreaks++; } } } return ret; } }