Java

Ben Coffman ben_coffman at hotmail.com
Mon May 3 12:45:40 CDT 2004


well yes if it was a holiday inn I have complete faith.

From: Jeremy Turner <jeremy at linuxwebguy.com>
To: Ben Coffman <ben_coffman at hotmail.com>
CC: kclug at kclug.org
Subject: Re: Java
MIME-Version: 1.0
Microsoft SMTPSVC(5.0.2195.6824); Sat, 1 May 2004 16:25:53 -0700
mc1-f31.hotmail.com with Microsoft SMTPSVC(5.0.2195.6824); Sat, 1 May 2004 
16:25:10 -0700
marauder.illiana.net (8.12.10/8.12.10) with ESMTP id i41MDFOv003447for 
<kclug-list at marauder.illiana.net>; Sat, 1 May 2004 17:13:15 -0500
(8.12.10/8.12.1/Submit) id i41MDFKW003446for kclug-list; Sat, 1 May 2004 
17:13:15 -0500
(dsl093-170-037.sfo4.dsl.speakeasy.net [66.93.170.37])by 
marauder.illiana.net (8.12.10/8.12.10) with ESMTP id i41MDDOv003441for 
<kclug at kclug.org>; Sat, 1 May 2004 17:13:14 -0500
helo=[192.168.0.5])by optimus.linuxwebguy.com with asmtp (Exim 4.31)id 
1BK3fY-0000lm-5i; Sat, 01 May 2004 16:13:16 -0700
X-Message-Info: TiNwL5K19MGDlz2lB3qdBDql128SY28zrheYmyTokC0=
X-Authentication-Warning: marauder.illiana.net: majordom set sender to 
owner-kclug at kclug.org using -f
In-Reply-To: <BAY16-F93vhDKUYzs2c0002a86c at hotmail.com>
References: <BAY16-F93vhDKUYzs2c0002a86c at hotmail.com>
Organization: http://linuxwebguy.com
Message-Id: <1083453161.18141.22.camel at athlonxp>
X-Mailer: Ximian Evolution 1.4.6
Precedence: bulk
Return-Path: owner-kclug at kclug.org
X-OriginalArrivalTime: 01 May 2004 23:25:10.0402 (UTC) 
FILETIME=[8BD82620:01C42FD3]

On Fri, 2004-04-30 at 15:34, Ben Coffman wrote:
 > I have a file I want to locate a word within the file and then erase that
 > word without erasing the rest of the file.  So far all I can get out of 
this
 > is to read in each character until I find the characters in the order I 
need
 > and then I know the location of the word and where I need to delete.

Nah... that sound's too much like C/C++ thinking.  Java deals more with
strings and tokens, rather than character arrays with null terminators.

Try something like this:

/*********/
import java.io.*;
import java.util.*;

public class delWord {

   public static void main (String av[]) {

     try {

       BufferedReader is = new BufferedReader(
         new InputStreamReader(System.in));
       String inputLine;
       StringBuffer outputLine;
       String wordToDelete = "and";
       StringTokenizer words;
       String curWord;

       while ((inputLine = is.readLine()) != null) {
         words = new StringTokenizer(inputLine);

         while (words.hasMoreTokens()) {
           curWord = st.nextToken();

           if (!curWord.equals(wordToDelete)) {
             System.out.print(curWord);
           }
         }
       }
       is.close();
     } catch (IOException e) {
       System.out.println("IOException: " + e);
     }
   }
}
/********/

Run this with:

$ java delWord < inputFile > outputFile

Something like that would work.  I'm not a certified Java hacker, but I
did stay a a Holiday Inn Express last night. :)

Jeremy

--
Jeremy Turner <jeremy at linuxwebguy.com>
http://linuxwebguy.com

_________________________________________________________________
Watch LIVE baseball games on your computer with MLB.TV, included with MSN 
Premium! 
http://join.msn.com/?page=features/mlb&pgmarket=en-us/go/onm00200439ave/direct/01/




More information about the Kclug mailing list