Chop Newlines





7
Date Submitted Tue. Mar. 14th, 2006 11:49 PM
Revision 1 of 1
Coder mattrmiller
Tags Java | Newline | REMOVE | Replace | String
Comments 4 comments
Remove newslines from a string.


// Chop newline
        public static String chopNewline(String str)
        {
                int lastIdx = str.length() - 1;
                if (lastIdx <= 0)
                {
                        return "";
                }
                char last = str.charAt(lastIdx);
                if (last == '\n')
                {
                        if (str.charAt(lastIdx - 1) == '\r')
                        {
                                lastIdx--;
                        }
                }
                else
                {
                        lastIdx++;
                }
                return str.substring(0, lastIdx);
        }
 

Matthew R. Miller

www.bluecreststudios.com
=================
Matthew R. Miller

http://bluecreststudios.com
http://www.codeandcoffee.com

Comments

Comments Unix/Mac file format
Sat. Oct. 28th, 2006 2:17 PM    Scripter SCoon
Comments Optimization
Fri. Sep. 22nd, 2006 8:15 PM    Newbie Kivanc_Anar
  Comments DOS/Windows only
Sat. Oct. 28th, 2006 2:19 PM    Scripter SCoon
Comments Isn't this much simpler?
Wed. Mar. 15th, 2006 6:12 AM    Scripter TimYates

Voting