Java String Sub String substringLinesWithTokenOfEOL( String originalString, String stringToBeInserted)

Here you can find the source of substringLinesWithTokenOfEOL( String originalString, String stringToBeInserted)

Description

Method to process String value with EOL mark

License

Open Source License

Parameter

Parameter Description
originalString :original string value to be processed
stringToBeInserted :value to be replaced into "#EOL#"(usually it's "\n")

Return

String :string value of processed string

Declaration

public static String substringLinesWithTokenOfEOL(
        String originalString, String stringToBeInserted) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from  www . j  a v  a 2  s . c o m
     * Method to process String value with EOL mark
     * @param originalString :original string value to be processed
     * @param stringToBeInserted :value to be replaced into "#EOL#"(usually it's "\n")
     * @return String :string value of processed string
     */
    public static String substringLinesWithTokenOfEOL(
            String originalString, String stringToBeInserted) {
        StringBuffer processedString = new StringBuffer();
        int lastEnd = 0;
        for (int i = 0; i <= originalString.length(); i++) {
            if (i + 5 <= originalString.length()) {
                if (originalString.substring(i, i + 5).equals("#EOL#")) {
                    processedString.append(originalString.substring(
                            lastEnd, i));
                    processedString.append(stringToBeInserted);
                    lastEnd = i + 5;
                }
            } else {
                if (i == originalString.length()) {
                    processedString.append(originalString.substring(
                            lastEnd, i));
                }
            }
        }
        return processedString.toString();
    }
}

Related

  1. substringFromMultiValuedFields(int start, int end, String[] fieldValues, int offsetGap, String interFieldJoiner)
  2. substringGuarded(String s, int position, int count)
  3. subStringIgnoreCase(String str, String separator, Integer stratNum, Integer endNum)
  4. substringInBetween(String name, String prefix, String delimiter)
  5. substringL(String s, int i, int len)
  6. substringMatch(CharSequence str, int index, CharSequence substring)
  7. substringMatch(CharSequence str, int index, CharSequence substring)
  8. substringMatches(final String source, final String substring, final boolean checkBoundaries)
  9. substringMore(String s, int maxlen)