CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2000
    Location
    Kaysville, UT
    Posts
    228

    find/replace question

    Is there any way to do a find/replace of carraige returns with linefeeds in VJ++ 6.0 Pro sp4?

    "There's nothing more dangerous than a resourceful idiot." ---Dilbert
    BWAHAHAHAHAHAHA! ---Murray

  2. #2
    Join Date
    Aug 2000
    Location
    U.K
    Posts
    25

    Re: find/replace question

    try this,


    try
    {

    buffer = new StringBuffer((int) toLoad.length());
    in = new InputStreamReader(new FileInputStream(toLoad));

    char[] buf = new char[BUFFER_SIZE];
    int len;
    int lineCount = 0;
    boolean CRLF = false;
    boolean CROnly = false;
    boolean lastWasCR = false;

    // we read the file till its end (amazing, hu ?)
    while ((len = in.read(buf, 0, buf.length)) != -1)
    {
    int lastLine = 0;
    for (int i = 0; i < len; i++)
    {
    // ++count;
    switch(buf[i])
    {
    // and we convert system's carriage return char into \n
    case '\r':
    if (lastWasCR)
    {
    CROnly = true;
    CRLF = false;
    } else
    lastWasCR = true;
    // if \r delete and replace with \n
    buffer.append(buf, lastLine, i - lastLine);
    buffer.append('\n');
    lastLine = i + 1;

    break;
    case '\n':
    if (lastWasCR)
    {
    CROnly = false;
    CRLF = true;
    lastWasCR = false;
    lastLine = i + 1;
    } else {
    CROnly = false;
    CRLF = false;
    buffer.append(buf, lastLine, i - lastLine);
    buffer.append('\n');
    lastLine = i + 1;
    }
    break;
    default:
    if (lastWasCR)
    {
    CROnly = true;
    CRLF = false;
    lastWasCR = false;
    }
    break;
    }
    }
    }
    in.close();
    in = null;

    if (buffer.length() != 0 && buffer.charAt(buffer.length() - 1) == '\n')
    buffer.setLength(buffer.length() - 1);







Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured