These two solutions are replacing tildes with carriage return characters (\r or \x0D). If you want line endings, then you should replace tildes with \n like someone else showed. That will turn into the line ending characters for your platform (CRLF, LF).