Help with deleting multiple strings from file.......

I am trying to delete the same string that may appear multiple times in the file. Here is the output to the screen. Here is the code. I have been researching the delete method it says that I have to start at an index position in the string but how would I find out where the multiples strings reside in the file? I am getting the feeling that it won't work for my purpose..???? I am trying to delete all ot the strings "a string of data3" from the file.
Output
C:\TestRead>java StringDelete
Temp String file_data-------- a string of data3a string of data2a string of data
1a string of data3a string of data2a string of data1a string of data3
Just A Blank Line
Just A Blank Line
Just A Blank Line
String toDelete-------- a string of data3
Just A Blank Line
Just A Blank Line
Just A Blank Line
String toDelete-------- a string of data2
Just A Blank Line
Just A Blank Line
Just A Blank Line
String toDelete-------- a string of data1
Just A Blank Line
Just A Blank Line
Just A Blank Line
String toDelete-------- a string of data3
Just A Blank Line
Just A Blank Line
Just A Blank Line
String toDelete-------- a string of data2
Just A Blank Line
Just A Blank Line
Just A Blank Line
String toDelete-------- a string of data1
Just A Blank Line
Just A Blank Line
Just A Blank Line
String toDelete-------- a string of data3
Just A Blank Line
Just A Blank Line
Just A Blank Line
Code:
import java.io.*;
public class StringDelete
public static void main(String [] args)
try
FileInputStream fis = new FileInputStream("TestFile.txt");
DataInputStream in = new DataInputStream(fis);
StringBuffer file_data = new StringBuffer();
while(in.available() > 0)
String temp = in.readUTF(); // read in a string from the file
file_data.append(temp); // append it to the buffer
System.out.println("Temp String file_data-------- " + file_data);
System.out.println("Just A Blank Line");
System.out.println("Just A Blank Line");
System.out.println("Just A Blank Line");
boolean keepGoing = true;
while(keepGoing)
String toDelete = file_data.substring(0, "a string of data3".length());
System.out.println("String toDelete-------- " + toDelete);
System.out.println("Just A Blank Line");
System.out.println("Just A Blank Line");
System.out.println("Just A Blank Line");
if(toDelete == null || toDelete.equals("") )
keepGoing = false;
else
file_data.delete(0,"a string of data3".length());
catch(IOException e)
e.printStackTrace();

Here is the output. I am trying to get each part to work before I go on to the next part that is why some code is commented out.
I need help to know why string "a string of data3" is not deleted in the towrite string??
Output:
C:\TestRead>java NewStringDelete
String v after remove [ ◄a string of data3 ◄a string of data2 ◄a string of data1
◄a string of data3 ◄a string of data2 ◄a string of data1 ◄a string of data3]
String towrite after remove ◄a string of data3 ◄a string of data2 ◄a string of
data1 ◄a string of data3 ◄a string of data2 ◄a string of data1 ◄a string of data
3
Code:
import java.util.Vector;
import java.io.*;
public class NewStringDelete
     public static void main(String [] args)
          //String ls = System.getProperty("line.separator");
          //File file;
          Vector v=new Vector();
     try{
          BufferedReader br=new BufferedReader(new FileReader ("TestFile.txt"));
          String s;
          while ((s=br.readLine())!=null)
               {v.addElement(new String(""+s));}
                    br.close();
     catch(IOException e)
               e.printStackTrace();
/*now you have a Vector containing String objects..*/
     String remove = ("a string of data3");
     String towrite="";
System.out.println("String v after remove " + v);     
     for (int i=0; i<v.size();i++)
          String ss = (String)v.elementAt(i);
          if (ss.equalsIgnoreCase(remove)){continue;}
          //     towrite=towrite+ss+ls;
               towrite=towrite+ss;
System.out.println("");               
System.out.println("");               
System.out.println("String towrite after remove " + towrite);                    
/*do filewrite*/
//try{
// FileWriter fw=new FileWriter(TestFile.txt);
// fw.write(towrite);
// fw.close();
// catch(IOException e)
//               e.printStackTrace();

Similar Messages

  • Help with deleting EFTFile1.sparseimage from my iMac

    Hello guys! I need real hands-on practical help here, please.
    I have already asked for help in here but didn't manage to get clear step by step help. Only got confusing redirection to other posts and very technical advice which really confuses me.
    First of all, I have an iMac8,1 with Snow Leopard 10.6.7. Memory 2GB 800 MHz DDR2 SDRAM, and before the problem occured I had about 260-270 GB of free space out of about 320 GB.
    I have discovered that my recycling bin contained a folder Recovered Files with a file EFTFile1.sparseimage. I only noticed it when I tried to Secure Empty the  Trash after running the tool Secure Delete Free Space from Internet Cleanup by SmithMicro (I don't know if this might be the cause of the problem).
    When I got to deleting stuff from the Trush I noticed it was taking too long, so I decided to transfer the various files out of the trush and delete them individually. When I reached the EFTFile1.sparseimage I discovered this was about 261 GB in size - when I tried opening it, it said the following:
    The following disk images couldn't be opened. Reason: corrupt image
    After reading some online forums, I now understand that by deleting this sparseimage file I should be able to recover the free space. Some people suggested to use Terminal. Their instructions have been very confusing and also when I attempted once in Terminal, before submitting anything, a warning said I might loose important files.
    Then someone suggested to write in Terminal the following:
    hdiutil compact followed by the path of the sparseimage file, i.e. path/sparseimagefilename
    After performing this the following message appeared: compact failed - corrupt image
    I want to stress, this EFTFile1.sparseimage isn't something I created (some forums have mentioned the possibility that some people may have done that for other purposes). The file appeared on my mac by itself. I guess, after using the SmithMicro free space delete?!
    If anyone has the patience and knows of a real solution for this problem, I would greatly appreciate your help.
    Cheers guys!

    Hello jsd2! 
    Your tip worked wonders! Thank you a million for suggesting the use of Trash It!
    Hurray!
    PS -
    From now on I will try using Disk Utility when deleting and be more careful when erasing free space, ensuring the process isn't interrupted. 
    Just in reply to noondaywitch, the reason I used Internet Cleanup from SmithMicro is simply because when I bought it a) I didn't know the full purpose of Disk Utility, b) when I was in the Apple shop they had Internet Cleanup on their shelf, so I assumed it was a good product to use - afterall, you assume that the products you see in their shops are endorsed by Apple, therefore good to use. Don't you think?

  • I deleted multiple responses from my FormCentral that had file attachments - anyway to get those back?

    I deleted multiple responses from my FormCentral that had file attachments - anyway to get those back?

    Thanks for the reply Michael. Here is more detailed info.
    Over time, I copied CDs into itunes with my old laptop and synced them with my iphone. That laptop died so I now have a new PC where I set it to manually manage music.
    I had my 'copied from CDs' songs together with 'purchased directly from iphone / itunes' songs on my iphone. I also had playlists on the phone containing a mix of this music.
    I thought by activating Match, all my music contained on my iphone would be copied to the cloud. That didn't happen.
    Now I have lost all my music from CDs off my phone, along with all my playlists.
    The strange thing is when I connect my iphone to the PC that is set to manually manage music, I can see those lost playlists and those lost songs in the playlists, however when I click on the song I get the exclimation point.
    Are the song files stored somewhere on my phone or PC? Is there anyway to get that music back?
    Thanks for your help.

  • How do I delete multiple photos from the Camera Roll?

    How do I delete multiple photos from camera roll without doing it one at a time?

    Thanks for your posts on this - it's something I've been wondering about, too.
    I do agree with Bonzo that it seems strange that there isn't a way to do it *efficiently* without having to hook the iPad to a computer.
    I know there is an alternative: in other words, you're right, Lawrence - it is possible to delete multiple files at once by following your instructions (i.e. tapping on each photo once, etc.) - but if you want to delete lots of photos, it takes ages to tap on every one of them.
    Does anyone else out there know of a way to delete multiple photos on the iPad/iPhone/iPod touch without having to tap on each photo separately, or having to hook up to a computer?
    I'd be really grateful for any help on this. Thanks!

  • Get specific Strings from File

    Good morning to every one.
    I 've got a text file which contains a customer number and an order number, coded as we see in the picture below:
    I am trying to develop a tool in Visual Studio, which it reads the file line-by-line and fills a listbox, with the order_number and the customer number. From the file above, I know that the order number are the digits on the first 'column' after the leading-zeros,
    until '/', and the customer number are the digits without zeros in the 'third' column before 'CUSTOMER_NUMBER'. My form looks like:
    The problem is, that the number of before the fields in file, are not equal in every line.
    So, my question is how I can retrieve the 'order number' and 'customer number' from the text file and copy the results to list box, after clicking on 'Get Strings' button, like:
    359962656   2238914
    359562804   2238914
    etc...
    I attach my code here:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.IO;
    namespace ReadStringFileApp
    public partial class frmMain : Form
    public frmMain()
    InitializeComponent();
    OpenFileDialog openfile = new OpenFileDialog();
    //openfiledialog to pickup filename
    private void btnFindFile_Click(object sender, EventArgs e)
    openfile.Filter = "Text|*.txt";
    if (openfile.ShowDialog() == DialogResult.OK)
    lbxResults.Items.Clear();
    txtFilepath.Text = openfile.FileName.ToString();
    //get strings from file
    private void btnGetStrings_Click(object sender, EventArgs e)
    //check if there is a file path on textbox
    if (txtFilepath.Text == "")
    MessageBox.Show("No File Select. Please select a file", "Error File Name", MessageBoxButtons.OK, MessageBoxIcon.Error);
    btnFindFile.Focus();
    return;
    //create list for all lines inside file
    List<string> lines = new List<string>();
    string line;
    using (StreamReader r = new StreamReader(@txtFilepath.Text))
    while ((line = r.ReadLine()) != null)
    string ordernum;//string for order number
    string customer;//string for customer number
    //line = ordernum + "\t" + customer; //concatenate results to fill the list box
    lbxResults.Items.Add(line);
    r.Close(); //close file
    private void btnExportToFIle_Click(object sender, EventArgs e)
    //check if listbox is empty
    if (lbxResults.Items.Count == 0)
    MessageBox.Show("Result List is empty! Choose a file to proceed.", "Error Result List", MessageBoxButtons.OK, MessageBoxIcon.Error);
    btnGetStrings.Focus();
    return;
    //read listbox contents and parse to a list object
    List<string> list = new List<string>();
    foreach (String i in lbxResults.Items)
    list.Add(i);
    //Create a file in c: with results
    File.WriteAllLines(@"C:\export-test.txt", list, Encoding.Default);
    MessageBox.Show("File export completed!", "File Export", MessageBoxButtons.OK, MessageBoxIcon.Information);
    Thank you in advanced

    @ Joel Engineer
    and@
    Val10
    I combined your responses and I get my results correctly. I attached the code I rewrite for further use:
    private void btnGetStrings_Click(object sender, EventArgs e)
    //check if there is a file path on textbox
    if (txtFilepath.Text == "")
    MessageBox.Show("No File Select. Please select a file", "Error File Name", MessageBoxButtons.OK, MessageBoxIcon.Error);
    btnFindFile.Focus();
    return;
    //create list for all lines inside file
    List<string> lines = new List<string>();
    string line;
    using (StreamReader r = new StreamReader(@txtFilepath.Text))
    while ((line = r.ReadLine()) != null)
    string order_customer;
    Regex reg = new Regex("0*");
    //set an string array, to split the file in columns positions, defining the characters
    string[] daneio = line.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
    //get order number from the first column
    var ordernum_zeros = reg.Match(daneio[0]).Value;
    daneio[0] = daneio[0].Replace(ordernum_zeros, String.Empty);
    daneio[0] = daneio[0].Substring(0, daneio[0].IndexOf("/"));
    //get customer column, without zeros
    var customer_zeros = reg.Match(daneio[5]).Value;
    daneio[2] = daneio[2].Replace(customer_zeros, String.Empty);
    daneio[2] = daneio[2].Substring(0, daneio[5].IndexOf("CUSTOMER_NUMBER"));
    //combine the result in listbox
    order_customer = daneio[0] + "\t" + daneio[2];
    lbxResults.Items.Add(order_customer);
    r.Close(); //close file
    Thank you for your help!

  • Delete Multiple Records from Item Master

    Hi,
    We received wrong master data which has been uploaded and two groups have to be deleted. All the items in those particular groups have also to be deleted. Can anyone suggest how to delete multiple records from Item Master?
    Currently I am navigating through each Item and doing a Right Click + Remove. It is very painful given the huge number of records.
    Regards
    Sudatt

    Hi Sudatt.....
    I recommend you not to run any kind of delete or update SQL query as it harms DB.
    You can create your own front end application with the help of any technical consultant which can be
    achieved very easily. Else such problems create a big problem during upgradation to next version.......
    Regards,
    Rahul

  • I cannot delete multiple entries from table

    Hi
    i am trying to delete multiple entries from table while keeping some data.
    for example I have the following table
    Plant                            Item
    US101                         777
    US101                         888
    US101                         999
    US101                         666
    I want to keep the  rows where the item is 777 and 888 for plant US101 and keep delete the rest data
    I wrote the following code
    Delete source_package where Plant = 'US101' and Item NE '777' or '888'.
    but all the rows get deleted.
    I tried deleting single row and it worked.
    Delete source_package where Plant = 'US101' and Item NE '777' .
    How can I delete multiple rows.
    thanks

    Hi Bhat Vaidya,
    Plz refer the following code.. IT will solve ur problem..
    REPORT  ZSDN_TEST.
    data: BEGIN OF it_data OCCURS 10,
            plant(4),
            item_num TYPE string,
          END OF it_data.
    data: str type string.
    data: it_final like it_data OCCURS 10 WITH HEADER LINE.
    it_data-plant = 'US01'. it_Data-item_num = 777.  append it_data.
    it_data-plant = 'US01'. it_Data-item_num = 888.  append it_data.
    it_data-plant = 'US01'. it_Data-item_num = 999.  append it_data.
    it_data-plant = 'US01'. it_Data-item_num = 666.  append it_data.
    delete it_data where plant = 'US01' and item_num ne 777 and item_num ne 888.
    LOOP AT it_data.
    write:it_data-plant,it_data-item_num.
    skip.
    ENDLOOP.
    Regards,
    Apoorv

  • How to delete multiple rows from ADF table

    How to delete multiple rows from ADF table

    Hi,
    best practices when deleting multiple rows is to do this on the business service, not the view layer for performance reasons. When you selected the rows to delete and press submit, then in a managed bean you access thetable instance (put a reference to a managed bean from the table "binding" property") and call getSeletedRowKeys. In JDeveloper 11g, ADF Faces returns the RowKeySet as a Set of List, where each list conatins the server side row key (e.g. oracle.jbo.Key) if you use ADF BC. Then you create a List (ArrayList) with this keys in it and call a method exposed on the business service (through a method activity in ADF) and pass the list as an argument. On the server side you then access the View Object that holds the data and find the row to delte by the keys in the list
    Example 134 here: http://blogs.oracle.com/smuenchadf/examples/#134 provides you with the code
    Frank

  • How to delete multiple songs from iPhone 5S without losing form iTunes? The unchek function has not worked. Why?

    How to delete multiple songs from iPhone 5S without losing form iTunes? The unchek function has not worked. Why?

    Sorry I had to reply through your profile Gail from Maine, my PC has java issues. In any event, when I delete them directly from my device everything is perfect and cool. However, in the rare instance I want to add new music that I actually buy in stores (I know, quite the unique and old-fashioned idea...but hey Im an audiophile) once I upload the tunes, everytime I sync my library it re-adds everything that I spent hours deleting. In a perfect world, I thought I could maintain a massive iTunes Library, and add or delete (remove) songs from my iPhone to save both memory or keep my iPhone selections more current/apt to my musical "tastes" at that time. I know about the whole playlist thing, but thought there might be an easier way. ie - checking/un-checking the little box next to the song name, and then doing a sync. Again, everytime I do this however, whether everything is checked or un-checked it adds the entire library! So frustrating. Any suggestions. Thank you graiously in advance for your help.

  • How to delete multiple playlists from itunes

    how to delete multiple playlists from itunes?

    Have you subscribed to iTunes Match? There is a bug that can sometimes create hundreds of duplicate empty playlists. I've two scripts which might help you clean up: KillEmptyPlaylists and KillTopLevelPlaylists. This post describes a technique for resetting iTunes Match to stop it happening again.
    tt2

  • How to delete multiple photos from updated iPhoto

    How to delete multiple photos from the updated iPhoto

    1 - there is no updated iPhoto - iPhoto is still on your computer and version 9.6.1 is probably the last version - there are no updates planned to iPhoto
    2 - Photos is a new photo management program built into OS X 10.10.3
    3 - Assuming you are talking about Photos  select the photos and press delete - they then go to the recently deleted photos album (show recently deleted under th file menu) where they sit for 30 days and then are automatically deleted unless you manually delete them first
    LN

  • Best practice for deleting multiple rows from a table , using creator

    Hi
    Thank you for reading my post.
    what is best practive for deleting multiple rows from a table using rowSet ?
    for example how i can execute something like
    delete from table1 where field1= ? and field2 =?
    Thank you

    Hi,
    Please go through the AppModel application which is available at: http://developers.sun.com/prodtech/javatools/jscreator/reference/codesamples/sampleapps.html
    The OnePage Table Based example shows exactly how to use deleting multiple rows from a datatable...
    Hope this helps.
    Thanks,
    RK.

  • Posting  multiple records from file to idoc

    Hi Exerts,
       i have done scenario to post one record from file to IDOC, to post multiple records from file to idoc what are the options to be modified in the scenario.
    thanks,
    dhanush

    Hi Dhanush,
      You need to change the occurance of idoc to 0 to unbounded ie need to opt idoc packaging.
      Just download the xsd of you idoc to the desktop and change the occurance tag as "<xsd:element name="IDOC" type="COND_A.COND_A02" maxOccurs="unbounded" />" and then reimport it into External definition and use it in your message mapping and then map it with you source structure.
    Regards,
    Prasanthi.

  • Delete multiple photos from ipad in ios7

    How do you delete multiple photos from ipad in ios7?  I need to clear out old photos to free up some space and don't want them deleted from other devices.  Also, what is the best source to learn how photos are shared, streamed, etc.  I assume that streaming photos do show up as taking up space on the ipad, but I want to understant how it all works between devlces.

    Hey dddog,
    To delete multiple photos at once:
    Tap Select, select the photos or videos you want to delete, then tap.
    You can even delete full albums:
    Manage albums. While viewing your album list, tap Edit.Delete an album:  Tap .
    via: Organize your photos and videos
    http://help.apple.com/iphone/7/#/iphf14943e
    All the best,
    Delgadoh

  • Deleting Multiple Rows From Multiple Tables As an APEX Process

    Hi There,
    I'm interesting in hearing best practice approaches for deleting multiple rows from multiple tables from a single button click in an APEX application. I'm using 3.0.1.008
    On my APEX page I have a Select list displaying all the Payments made and a user can view individual payments by selecting a Payment from the Select List (individual items are displayed below using Text Field (Disabled, saves state) items with a source of Database Column).
    A Payment is to be deleted by selecting a custom image (Delete Payments Button) displayed in a Vertical Images List on the same page. The Target is set as the same page and I gave the Request a name of DELETEPAY.
    What I tried to implement was creating a Conditional Process On Submit - After Computations and Validations that has a source of a PL/SQL anonymous block as follows:
    BEGIN
    UPDATE tblDebitNotes d
    SET d.Paid = 0
    WHERE 1=1
    AND d.DebitNoteID = :P7_DEBITNOTEID;
    INSERT INTO tblDeletedPayments
    ( PaymentID,
    DebitNoteID,
    Amount,
    Date_A,
    SupplierRef,
    Description
    VALUES
    ( :P7_PAYMENTID,
    :P7_DEBITNOTEID,
    :P7_PAID,
    SYSDATE,
    :P7_SUPPLIERREF,
    :P7_DESCRIPTION
    DELETE FROM tblPayments
    WHERE 1=1
    AND PaymentID = :P7_PAYMENTID;
    END;
    The Condition Type used was Request = Expression 1 where Expression 1 had a value of DELETEPAY
    However this process is not doing anything!! Any insights greatly appreciated.
    Many thanks,
    Gary.

    ...the "button" is using a page level Target,...
    I'm not sure what that means. If the target is specified in the definition of a list item, then clicking on the image will simply redirect to that URL. You must cause the page to be submitted instead, perhaps by making the URL a reference to the javaScript doSubmit function that is part of the standard library shipped with Application Express. Take a look at a Standard Tab on a sample application and see how it submits the page using doSubmit() and emulate that.
    Scott

Maybe you are looking for

  • Jabber for Windows login to the IM&P but not to the CUCM

    Hi, I have Jabber for Windows, IM and Presence Server 10.5 and CUCM 10.5. The problem is it says it cannot communicate with the server upon logging in. But if I typed a wrong username / password it says "Your username and password is not correct."  W

  • Unable to release the change request from se01

    HI All, Recently i had applied Rsecnotes as per sap recommendation in EWA Report and I implemented successfully in DEV System. But, When i try to release the change requests from SE01 in (DEV System) it is giving the error message "Object Func<object

  • Photo not in iPhoto?

    After uploading pics to iPhoto, I open some of the better ones in PE3 for "post processing." If it was originally a JPEG, I save it in exactly the same location (usually by date) it came from but with a different name, but still as a JPEG again. When

  • Can I call a function from a dll in LabVIEW that returns:double*string and int.?

    I have a function from a dll that return a double* string and an integer. How can I call this function from LabVIEW? There is a possibility to work in LabVIEW with a double* string?

  • Classic scenario CUF to R3

    I've been reading about Extended Classic Scenario (ECS) and how to get customer fields (CUF) to R3 using a BADI. Is something possible for the classic scenario also? I've defined CUF in INCL_EEW_PD_ITEM_CSF* and they show up, but I want to map the CU