REGEXP_SUBSTR read whole lines

Hi,
I'm trying to work with REGEXP_SUBSTR.
But I’ve a problem with it:
For example I’ve this text in a varchar field:
SCAFFOLD REF: 529
LOCATION: CD4
DATE OF ERECTION: 120607
LAST INSPECTION: 110308
LADDER INSPECTION DATE: 110308
COMMENTS: Scaffold OK - issue over time logged at inspection
IO130 am this appears to be on all tags
DATE SIGNED: 170308
Now I want all the text from "COMMENTS" (without “comment”) until DATE also without date itself. Is that possible?
Thanks

Hi,
Maybe another approach is to remove all data before "COMMENTS:" and after "DATE SIGNED:". Because using regexp_substr, you will not be able to get rid of "COMMENTS: " and "DATE SIGNED: ". See example below :
SQL> drop table t;
Table dropped
SQL> create table t(info varchar2(1000));
Table created
SQL> insert into t(info)
2 values ('SCAFFOLD REF: 529
3 LAST INSPECTION: 110308
4 LADDER INSPECTION DATE: 110308
5 COMMENTS: Scaffold OK - issue over time logged at inspection
6 IO130 am this appears to be on all tags
7
8 DATE SIGNED: 170308');
1 row inserted
SQL> select regexp_replace(info, '([^,]*COMMENTS: )([^,]*)(DATE SIGNED: [^,]*)', '\2') as regexp_replace from t;
REGEXP_REPLACE
Scaffold OK - issue over time logged at inspection
IO130 am this appears to be on all tags
SQL>
regards,
François

Similar Messages

  • File-Sender: Probl. with Content conversion - Read whole line in singleTag

    Hello,
    I have a flat file that i read with the sender file adapter.
    After content conversion I get not the result i wished to have...
    The source flat file looks for example like this:
    ABC;DEF;GHIJ
    KLM;NOP;Q
    RSTU;VW
    After the Content Conversion I would like to have this result:
    <Recordset>
         <Data>
              <Row>ABC;DEF;GHIJ
               <Row>KLM;NOP;Q
              <Row>RSTU;VW
              <……>
    What sounds very similar but didn’t work for me yesterday….
    I defined a data type that looked like this:
    DT_TEST (Complex Type)
         Recordset (0..unbounded)
              Data (1)
                   Row (type string / 0..unbounded)
    During the file content conversion I just did this:
    Recordsetname: Recordset
    Recordset structure: Data, 1
    Data.fieldNames = Row
    Data.fieldSeparator = ‘nl’
    This was also described in blog:
    /people/sravya.talanki2/blog/2005/08/16/configuring-generic-sender-file-cc-adapter
    But my result is always like this:
    <Recordset>
         <Data>
              <Row>ABC;DEF;GHIJ
         </Data>
    </Recordset>
    <Recordset>
         <Data>
              <Row> KLM;NOP;Q
         </Data>
    </Recordset>
    <Recordset>
         <Data>
              <Row> RSTU;VW
         </Data>
    </Recordset>
    ….And not like I wished….
    Can anybody help me…?
    Greetings
    Tobias

    Hi,
    I just gone thru the blog and as per the structure defined I have no idea how this works this way.
    But if you modify the structure to
    RecordSet - occurs 0-1
    Data - occurs 0-n
    Row - occurs 0-1
    And in the Content conversion mentions Data,* instead of Data,1.
    In this case you will be getting a output like
    <Data>
      <Row>ddf,sdfsd,sdf</Row>
    </Data>
    <Data>
      <Row>fff,sdfsd,sdf</Row>
    </Data>
    You can achieve this but I don't have any idea how to generate that kind of output with the Structure and the conversion parameter mentioned in the blog.
    Thanks,
    Prakash

  • I wanna dots instead of displaying it as a whole line in Linechart

    Hi Folks,
    I had one small doubt in the output of this program. The program is related to LineChart..Actually, Im getting the output as Line in the chart, but my requirement is to display only dots instead of displaying as a line...
    I just want only displaying as dots at particular name, insteading of getting that whole line from beginning to end...
    First of all whether its posiible to get dots or not?? and if it is possible, how??
    Here is the code:
    package com.home.practise.streams;
    import java.awt.BasicStroke;
    import java.awt.Color;
    import java.awt.Polygon;
    import java.awt.Shape;
    import java.awt.geom.Rectangle2D;
    import org.jfree.chart.ChartFactory;
    import org.jfree.chart.ChartPanel;
    import org.jfree.chart.JFreeChart;
    import org.jfree.chart.axis.NumberAxis;
    import org.jfree.chart.plot.CategoryPlot;
    import org.jfree.chart.plot.DefaultDrawingSupplier;
    import org.jfree.chart.plot.DrawingSupplier;
    import org.jfree.chart.plot.PlotOrientation;
    import org.jfree.chart.renderer.category.LineAndShapeRenderer;
    import org.jfree.data.category.CategoryDataset;
    import org.jfree.data.category.DefaultCategoryDataset;
    import org.jfree.ui.ApplicationFrame;
    import org.jfree.ui.RefineryUtilities;
    public class LineChartDemo5 extends ApplicationFrame {
        public LineChartDemo5(final String title) {
            super(title);
            final CategoryDataset dataset = createDataset();
            final JFreeChart chart = createChart(dataset);
            final ChartPanel chartPanel = new ChartPanel(chart);
            chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
            setContentPane(chartPanel);
        private CategoryDataset createDataset() {
            // row keys...
            final String series1 = "First";
            final String series2 = "Second";
            final String series3 = "Third";
            // column keys...
            final String type1 = "Hari";
            final String type2 = "Chary";
            final String type3 = "Trinetra";
            final String type4 = "Naveen";
            final String type5 = "Type 5";
            final String type6 = "Type 6";
            final String type7 = "Type 7";
            final String type8 = "Type 8";
            // create the dataset...
            final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
            dataset.addValue(0, series1, type1);
            dataset.addValue(0, series1, type2);
            dataset.addValue(1, series1, type3);
            dataset.addValue(1, series1, type4);
            /*dataset.addValue(5.0, series1, type5);
            dataset.addValue(7.0, series1, type6);
            dataset.addValue(7.0, series1, type7);
            dataset.addValue(8.0, series1, type8);*/
            /*dataset.addValue(5.0, series2, type1);
            dataset.addValue(7.0, series2, type2);
            dataset.addValue(6.0, series2, type3);
            dataset.addValue(8.0, series2, type4);
            dataset.addValue(4.0, series2, type5);
            dataset.addValue(4.0, series2, type6);
            dataset.addValue(2.0, series2, type7);
            dataset.addValue(1.0, series2, type8);
            dataset.addValue(4.0, series3, type1);
            dataset.addValue(3.0, series3, type2);
            dataset.addValue(2.0, series3, type3);
            dataset.addValue(3.0, series3, type4);
            dataset.addValue(6.0, series3, type5);
            dataset.addValue(3.0, series3, type6);
            dataset.addValue(4.0, series3, type7);
            dataset.addValue(3.0, series3, type8);*/
            return dataset;
        private JFreeChart createChart(final CategoryDataset dataset) {
            final JFreeChart chart = ChartFactory.createLineChart(
                "visualization",      // chart title
                "Names",                   // domain axis label
                "Gender",                  // range axis label
                dataset,                  // data
                PlotOrientation.VERTICAL, // orientation
                true,                     // include legend
                true,                     // tooltips
                false                     // urls
    //        final StandardLegend legend = (StandardLegend) chart.getLegend();
      //      legend.setDisplaySeriesShapes(true);
            final Shape[] shapes = new Shape[3];
            int[] xpoints;
            int[] ypoints;
            // right-pointing triangle
            xpoints = new int[] {-3, 3, -3};
            ypoints = new int[] {-3, 0, 3};
            shapes[0] = new Polygon(xpoints, ypoints, 3);
            // vertical rectangle
            shapes[1] = new Rectangle2D.Double(-2, -3, 3, 6);
            // left-pointing triangle
            xpoints = new int[] {-3, 3, 3};
            ypoints = new int[] {0, -3, 3};
            shapes[2] = new Polygon(xpoints, ypoints, 3);
            final DrawingSupplier supplier = new DefaultDrawingSupplier(
                DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE,
                DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE,
                DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE,
                DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE,
                shapes
            final CategoryPlot plot = chart.getCategoryPlot();
            plot.setDrawingSupplier(supplier);
            chart.setBackgroundPaint(Color.yellow);
            // set the stroke for each series...
            plot.getRenderer().setSeriesStroke(
                0,
                new BasicStroke(
                    2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
                    1.0f, new float[] {10.0f, 6.0f}, 0.0f
            plot.getRenderer().setSeriesStroke(
                1,
                new BasicStroke(
                    2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
                    1.0f, new float[] {6.0f, 6.0f}, 0.0f
            plot.getRenderer().setSeriesStroke(
                2,
                new BasicStroke(
                    2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
                    1.0f, new float[] {2.0f, 6.0f}, 0.0f
            // customise the renderer...
            final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    //        renderer.setDrawShapes(true);
            renderer.setItemLabelsVisible(true);
         //   renderer.setSeriesLinesVisible(0, false);
       //     renderer.setBaseLinesVisible(false);
      //      renderer.setBaseShapesVisible(true);
      //      renderer.setSeriesLinesVisible(1, true);
      //      renderer.setLabelGenerator(new StandardCategoryLabelGenerator());
            // customise the range axis...
            final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
            rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
            rangeAxis.setAutoRangeIncludesZero(false);
            rangeAxis.setUpperMargin(0.12);
            return chart;
        public static void main(final String[] args) {
            final LineChartDemo5 demo = new LineChartDemo5("Line Chart Demo 5");
            demo.pack();
            RefineryUtilities.centerFrameOnScreen(demo);
            demo.setVisible(true);
    }And here is the link, I have just used the above program from this link only
    http://www.java2s.com/Code/Java/Chart/JFreeChartLineChartDemo5showingtheuseofacustomdrawingsupplier.htm

    It looks like you're using BasicStrokes to create dashed lines
    plot.getRenderer().setSeriesStroke(
        0,
        new BasicStroke(
            2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
            1.0f, new float[] {10.0f, 6.0f}, 0.0f
    plot.getRenderer().setSeriesStroke(
        1,
        new BasicStroke(
            2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
            1.0f, new float[] {6.0f, 6.0f}, 0.0f
    plot.getRenderer().setSeriesStroke(
        2,
        new BasicStroke(
            2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
            1.0f, new float[] {2.0f, 6.0f}, 0.0f
    ); Is this not what you want? If you want points instead of dashes you just specify *1f* for first argument in the float array
    new BasicStroke(...,...,...,...,new float[]{1f,6f},....); That indicates that you want the dashed regions to be ~1 pixel long - that is, a point - and the empty regions between the dashes to be ~6 pixels long.

  • ITunes doesn't display the whole line

    Most of my iTunes looks like this:
    I have plenty of space on the screen, but can't see the whole line. Anyone know how to fix it.

    You signature shows you have Mac OS X 10.7.4.
    If you do not have an Info tab in iTunes, you have Mac OS X 10.9.
    You sync Contacts & Calendars using iCloud, not iTunes.

  • JTable - color a whole line

    Hi Everybody!
    I want to do the following:
    Create a simple JTable and color some lines with different colors, not only a single cell, but a whole line, using a ColorModel.
    Can anyone be so kind and provide me some pseudo-code or an example implementation for how to do this?
    I have really gotten stuck and I have no idea how to do this.
    Thx in Advance!
    StrongSteve

    Read this:
    http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#renderer
    Then, make your own renderer. Based on the row number, set the background color to whatever you want.

  • When I highlight a word..it highlights the whole line

    I am trying to edit in the timeline and when I highlight a word or text and release it it highlights the whole line not the selected words.
    thanks
    Naru

    It sounds like you need to change your path operations?
    Is it showing:
    change to:

  • AppleScript to delete the whole line if ..

    Im using the following code to find and replace with "target word" but I would like to DELETE the whole line instead of replacing the actual word.
    so it would be
    if the line contains www.network -> Delete the whole line.
    Thanks in advance!
    set theTargetWords to {"www.network"}
    tell application "Pages" to activate
    tell application "System Events" to tell process "Pages"
      -- Open the "Find & Replace" window:
      keystroke "f" using command down
              repeat until exists window "Find & Replace"
              end repeat
              tell tab group 1 of window "Find & Replace"
      -- Adjust the settings:
      click radio button 2 -- Advanced
                        if value of checkbox 2 is 1 then click checkbox 2 -- Don't match case
                        if value of checkbox 3 is 1 then click checkbox 3 -- Whole words
                        if value of checkbox 1 is 0 then click checkbox 1 -- Search previous text (loop)
      click pop up button 1 -- find in
      click menu item 1 of menu 1 of pop up button 1 -- Entire document
      click pop up button 2 -- replace style
      click menu item 1 of menu 1 of pop up button 2 -- Any
      -- Delete every target word:
                        set value of text area 1 of scroll area 2 to ""
                        repeat with thisWord in theTargetWords
                                  set value of text area 1 of scroll area 1 to thisWord -- the target word
                                  click button "Replace All"
                        end repeat
              end tell
    end tell

    if you want to script an application, read and use the application scripting dictionary. using System Events to script the GUI is something you should only do as a last resort. It creates clunky, slow, overly complex, and breakable scripts.
    try this to start:
    tell application "Pages"
              delete (every paragraph of body text of document 1 whose contents contains "some key phrase")
    end tell

  • While typing in an email, I can not delete or backspace a single letter. When I delete one letter, the whole line disappear.

    While typing in an email, I can not delete or backspace a single letter. When I delete one letter, the whole line disappear. I am using Window 7 and latest Firefox.
    == This happened ==
    Every time Firefox opened
    == Using Firefox on my new machine with Window 7.

    Start Firefox in [[Safe Mode]] to check if one of your add-ons is causing your problem (switch to the DEFAULT theme: Tools > Add-ons > Themes).
    See [[Troubleshooting extensions and themes]] and [[Troubleshooting plugins]]
    If it does work in Safe-mode then disable all your extensions and then try to find which is causing it by enabling one at a time until the problem reappears.
    You can use "Disable all add-ons" on the [[Safe mode]] start window to disable all extensions.
    You have to close and restart Firefox after each change via "File > Exit" (Mac: "Firefox > Quit"; Linux: "File > Quit")

  • Arraylist only reading first line of file

    I am reading a text file using an arraylist. my file has a single value on each line e.g.
    2
    3
    4
    5
    however this method is only reading only the first line of each file. is it because of this statement:
    String s1[] = number.split("\\s");
    I would like to change the method so its not expecting numbers in a single line.. but reads each line and adds it to the collection... how can I do that?
    here is getData method that gets the file and processes it.
         public static List<Integer> getData(String Filename) {
              List<Integer> array1 = null;
              // BufferedReader for file reverse.txt
              try {
                   array1 = new ArrayList<Integer>();
                   BufferedReader bf = new BufferedReader(new FileReader(Filename));
                   String number = bf.readLine();
                   String s1[] = number.split("\\s");
                   for (int i = 0; i < s1.length; i++)
                        array1.add(Integer.parseInt(s1));
              } catch (Exception e) {
                   e.printStackTrace();
              return array1;

    Faissal wrote:
    while(bf .ready()){
    readline() will return null if the end of the stream has been reached. ([http://java.sun.com/javase/6/docs/api/java/io/BufferedReader.html]). This condition can be used to determine when to stop reading thereby ensuring that all lines have been read.
    EDIT:
    Here's a code snippet from [Java Developers Almanac|http://www.exampledepot.com/egs/java.io/ReadLinesFromFile.html]: notice how they close() the stream when they're finished with it.

  • Reading one line from a text file into an array

    i want to read one line from a text file into an array, and then the next line into a different array. both arays are type string...i have this:
    public static void readAndProcessData(FileInputStream stream){
         InputStreamReader iStrReader = new InputStreamReader (stream);
         BufferedReader reader = new BufferedReader (iStrReader);
         String line = "";          
         try{
         int i = 0;
              while (line != null){                 
                   names[i] = reader.readLine();
                   score[i] = reader.readLine();
                   line = reader.readLine();
                   i++;                
              }catch (IOException e){
              System.out.println("Error in file access");
    this section calls it:
    try{                         
         FileInputStream stream = new FileInputStream("ISU.txt");
              HighScore.readAndProcessData(stream);
              stream.close();
              names = HighScore.getNames();
              scores = HighScore.getScores();
         }catch(IOException e){
              System.out.println("Error in accessing file." + e.toString());
    it gives me an array index out of bounds error

    oh wait I see it when I looked at the original quote.
    They array you made called names or the other one is prob too small for the amount of names that you have in the file. Hence as I increases it eventually goes out of bounds of the array so you should probably resize the array if that happens.

  • How can I input read a line from a file and output it into the screen?

    How can I input read a line from a file and output it into the screen?
    If I have a file contains html code and I only want the URL, for example, www24.brinkster.com how can I read that into the buffer and write the output into the screen that using Java?
    Any help will be appreciate!
    ======START FILE default.html ========
    <html>
    <body>
    <br><br>
    <center>
    <font size=4 face=arial color=#336699>
    <b>Welcome to a DerekTran's Website!</b><br>
    Underconstructions.... <br>
    </font> </center>
    <font size=3 face=arial color=black> <br>
    Hello,<br>
    <br>
    I've been using the PWS to run the website on NT workstation 4.0. It was working
    fine. <br>
    The URL should be as below: <br>
    http://127.0.0.1/index.htm or http://localhost/index.htm
    <p>And suddently, it stops working, it can't find the connection. I tried to figure
    out what's going on, but still <font color="#FF0000">NO CLUES</font>. Does anyone
    know what's going on? Please see the link for more.... I believe that I setup
    everything correctly and the bugs still flying in the server.... <br>
    Thank you for your help.</P>
    </font>
    <p><font size=3 face=arial color=black>PeerWebServer.doc
    <br>
    <p><font size=3 face=arial color=black>CannotFindServer.doc
    <br>
    <p><font size=3 face=arial color=black>HOSTS file is not found
    <br>
    <p><font size=3 face=arial color=black>LMHOSTS file
    <br>
    <p><font size=3 face=arial color=black>How to Setup PWS on NT
    <BR>
    <p><font size=3 face=arial color=black>Issdmin doc</BR>
    Please be patient while the document is download....</font>
    <font size=3 face=arial color=black><br>If you have any ideas please drop me a
    few words at [email protected] </font><br>
    <br>
    <br>
    </p>
    <p><!--#include file="Hits.asp"--> </p>
    </body>
    </html>
    ========= END OF FILE ===============

    Hi!
    This is a possible solution to your problem.
    import java.io.*;
    class AddressExtractor {
         public static void main(String args[]) throws IOException{
              //retrieve the commandline parameters
              String fileName = "default.html";
              if (args.length != 0)      fileName =args[0];
               else {
                   System.out.println("Usage : java AddressExtractor <htmlfile>");
                   System.exit(0);
              BufferedReader in = new BufferedReader(new FileReader(new File(fileName)));
              StreamTokenizer st = new StreamTokenizer(in);
              st.lowerCaseMode(true);
              st.wordChars('/','/'); //include '/' chars as part of token
              st.wordChars(':',':'); //include ':' chars as part of token
              st.quoteChar('\"'); //set the " quote char
              int i;
              while (st.ttype != StreamTokenizer.TT_EOF) {
                   i = st.nextToken();
                   if (st.ttype == StreamTokenizer.TT_WORD) {          
                        if (st.sval.equals("href")) {               
                             i = st.nextToken(); //the next token (assumed) is the  '=' sign
                             i = st.nextToken(); //then after it is the href value.               
                             getURL(st.sval); //retrieve address
              in.close();
         static void getURL(String s) {     
              //Check string if it has http:// and truncate if it does
              if (s.indexOf("http://") >  -1) {
                   s = s.substring(s.indexOf("http://") + 7, s.length());
              //check if not mailto: do not print otherwise
              if (s.indexOf("mailto:") != -1) return;
              //printout anything after http:// and the next '/'
              //if no '/' then print all
                   if (s.indexOf('/') > -1) {
                        System.out.println(s.substring(0, s.indexOf('/')));
                   } else System.out.println(s);
    }Hope this helps. I used static methods instead of encapsulating everyting into a class.

  • Does anyone know of an e-reader app for the iphone that has text to speech capability? I have a Kindle 3G that can read whole pdf documents and books but I cannot figure out how to do it on my iphone 4.

    Does anyone know of an e-reader app for the iphone that has text to speech capability? I have a Kindle 3G that can read whole pdf documents and books but I cannot figure out how to do it on my iphone 4.
    All of the apps I have found on the App store either do not have the text to speech capability or if they have it they will only read a page at a time or simply read the text you paste into their window. I really do not understand what is so difficult about having this feature as Kindle provides it--though Amazon does not make the feature available on its iPhone 4 app.
    Please help.

    thanks. yes i am aware of the VoiceOver feature but it is NOT the solution to my problem. as you said, it is a solution to a different set of issues. i want the text to speech ability because i there are books i need to read but do not have the time to sit down and read them and have become used to listening to them read to me either by a professional human reader or with the text to speech software on the Kindle.
    I think Apple makes the best audio devices but i am really disappointed in this inexplainable shortcoming. if apple can give us siri they ought to be able to design a nice little button that i can push to turn on text to speech while i am in a document, book, magazine or webpage. clearly it is possible as apple has added the "reader" button in safari to have web pages dropped into the reader format.
    thanks for your suggestion though, it is what everyone suggests but it does not address the issue.

  • How to read every line from a text file???

    How can i read every line from my text file ("eka.txt")
    now it only reads the first line and prints it out.
    What is wrong with this?
    import java.io.*;
    import java.util.*;
    class Testi{
         public static void main(String []args)throws IOException {
         BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));
    File inputFile = new File ("eka.txt");
    FileReader fis =new FileReader(inputFile);
    BufferedReader bis = new BufferedReader(fis);
    String test=bis.readLine();
    String tmp= "";
    while((bis.readLine().trim() != null)) {
    int spacefound=0;
    int l=test.indexOf(" ");
         for(int i=0;i<test.length();i++){
         char c=test.charAt(i);
         if(c!=' ') tmp+=""+c;
         if(c==' ' && (spacefound<1) && !(tmp.equals(""))){
         tmp+=""+c;
         spacefound++;
         if(tmp.length()==l) {
         System.out.println(tmp);
         tmp="";
         spacefound=0;
         if(tmp.length()<l){
         for(int i=0;i<=(l-tmp.length());i++)
         tmp+=""+' ';
         System.out.println(tmp);

    Try this code, Hope it servers your purpose.
    import java.io.*;
    import java.util.*;
    class Testi {
         public static void main(String []args)throws IOException {
              BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));
              File inputFile = new File ("Eka.txt");
              FileReader fis =new FileReader(inputFile);
              BufferedReader bis = new BufferedReader(fis);
              String test=bis.readLine();
              while(test != null) {
                   StringTokenizer st = new StringTokenizer(test," ");
                   while(st.hasMoreTokens())
                        System.out.println(st.nextToken());
                   test = bis.readLine();
    }Sudha

  • How to read some lines from a text file using java.

    hi,
    i m new to java and i want to read some lines from a text file based on some string occurrence in the file. This file to be read in steps.
    we only want to read the file upto the first Occurrence of "TEXT" string.
    How to do it ,,,
    Kinldy give the code
    Regards,
    Sagar
    this is the text file
    dfgjdjj
    sfjhjkd
    ghjkdg
    hjkdgh TEXT
    ikeyt
    ujt
    jk
    tyk TEXT
    rukl
    r

    Hendawy wrote:
    Since the word "TEXT" is formed of 4 letters, you would read the text file 4 bytes by four bytes. Wrong on two counts. First, the file may not be encoded 1 byte per character. It could be utf-16 in which case it would be two byte per character. Second, even if it were 1 byte per character, the string "Text" may not start on a 4 byte boundary.
    Consider a FileInputStream object "fis" that points to your text file. use fis.read(byte[] array, int offset, int len) to read every four bytes. Convert the "TEXT" String into a byte array "TEXT".getBytes(), and yous the Arrays class to compare the equality of the read bytes with your "TEXT".getBytes()Wrong since it relies on my second point and will fail when fis.read(byte[] array, int offset, int len) does not read 4 bytes (as is no guaranteed to). Check the Javadoc. Also, the file may not be encoded with the default character encoding.
    The problem is easily solved by reading a line at a time using a BufferedReader wrapping an InputStreamReader wrapping a FileInputStream and specifying the correct character encoding.
    Edited by: sabre150 on Apr 29, 2009 2:13 PM

  • Having trouble reading specific lines from a text file and displaying them in a listbox

    I am trying to read specific lines from all of the text files in a folder that are reports. When I run the application I get the information from the first text file and then it returns this error: "A first chance exception of type 'System.ArgumentOutOfRangeException'
    occurred in mscorlib.dll"
    Below is the code from that form. 
    Option Strict On
    Option Infer Off
    Option Explicit On
    Public Class frmInventoryReport
    Public Function ReadLine(ByVal lineNumber As Integer, ByVal lines As List(Of String)) As String
    Dim intTemp As Integer
    intTemp = lineNumber
    Return lines(lineNumber - 1)
    lineNumber = intTemp
    End Function
    Public Function FileMatches(ByVal folderPath As String, ByVal filePattern As String, ByVal phrase As String) As Boolean
    For Each fileName As String In IO.Directory.GetFiles(folderPath, filePattern)
    If fileName.ToLower().Contains(phrase.ToLower()) Then
    Return True
    End If
    Next
    Return False
    End Function
    Private Sub frmInventoryReport_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim intcase As Integer = 1
    Dim strTemp, strlist, strFile As String
    Dim blnCheck As Boolean = True
    strFile = "Report Q" & intcase.ToString & ".txt"
    Do While blnCheck = True
    strFile = "Report Q" & intcase.ToString & ".txt"
    Dim objReader As New System.IO.StreamReader("E:\Furry Friends Animal Shelter Solution\Furry Friends Animal Shelter\" & strFile)
    Dim allLines As List(Of String) = New List(Of String)
    Do While objReader.Peek <> -1
    allLines.Add(objReader.ReadLine())
    Loop
    objReader.Close()
    strlist = ReadLine(1, allLines) & "" & ReadLine(23, allLines)
    lstInventory.Items.Add(strlist)
    intcase += 1
    strTemp = intcase.ToString
    strFile = "Report Q" & intcase.ToString & ".txt"
    blnCheck = FileMatches("E:\Furry Friends Animal Shelter Solution\Furry Friends Animal Shelter\", "*.txt", intcase.ToString)
    Loop
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim intcase As Integer = 1
    Dim strTemp, strlist, strFile As String
    Dim blnCheck As Boolean = True
    strFile = "Report Q" & intcase.ToString & ".txt"
    Do While blnCheck = True
    strFile = "Report Q" & intcase.ToString & ".txt"
    Dim objReader As New System.IO.StreamReader("E:\Furry Friends Animal Shelter Solution\Furry Friends Animal Shelter\" & strFile)
    Dim allLines As List(Of String) = New List(Of String)
    Do While objReader.Peek <> -1
    allLines.Add(objReader.ReadLine())
    Loop
    objReader.Close()
    strlist = ReadLine(1, allLines) & "" & ReadLine(23, allLines)
    lstInventory.Items.Add(strlist)
    intcase += 1
    strTemp = intcase.ToString
    strFile = "Report Q" & intcase.ToString & ".txt"
    blnCheck = FileMatches("E:\Furry Friends Animal Shelter Solution\Furry Friends Animal Shelter\", "*.txt", intcase.ToString)
    Loop
    End Sub
    End Class
    Sorry I'm just beginning coding and I'm still a noob. Any help is appreciated. Thank you!

    Ok, so if I'm following this correctly you should be able to just loop through all of the files in that folder whose file name matches the pattern and then read the first 22 lines, recording only the first and the last.
    Exactly how you store the animal data probably depends on how you are going to display it and what else you are going to do with it.  Is there anything other than name and cage number that should be associated with each animal?
    You might want to make a dataset with a datatable to describe the animal, or you might write a class, or you might just use something generic like a Tuple.  Here's a simple class example:
    Public Class Animal
    Public Property Name As String
    Public Property Cage As String
    Public Overrides Function ToString() As String
    Return String.Format("{0} - {1}", Name, Cage)
    End Function
    End Class
    With that you can use a routine like the following to loop through all of the files and read each one:
    Dim animals As New List(Of Animal)
    Dim folderPath As String = "E:\Furry Friends Animal Shelter Solution\Furry Friends Animal Shelter\"
    For Each filePath As String In System.IO.Directory.GetFiles(folderPath, "Report Q?.txt")
    Using reader As New System.IO.StreamReader(filePath)
    Dim lineIndex As Integer = 0
    Dim currentAnimal As New Animal
    While Not reader.EndOfStream
    Dim line As String = reader.ReadLine
    If lineIndex = 0 Then
    currentAnimal.Name = line
    ElseIf lineIndex = 22 Then
    currentAnimal.Cage = line
    Exit While
    End If
    lineIndex += 1
    End While
    animals.Add(currentAnimal)
    End Using
    Next
    'do something to display the animals list
    Then you might bind the animals list to a ListBox, or loop through the list and populate a ListView.  If you decided to fill a datatable instead of making Animal instances, then you might bind the resulting table to a DataGridView.
    There are lots of options depending on what you want and what all you need to do.
    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

Maybe you are looking for

  • Is there a way to change the color of a linked eps or ai file in InDesign?

    I have a questionaire form that I'm placing in several documents. I need it to be exactly the same in all instances except that it occurs in 4/c on some docs and 1/c (black) on others. It'd be best to have all the Indesign files link to the same eps

  • Convert file encoding from ASMO-708 to Unicode

    Hi, I have txt files from a dos application. the files in ASMO-708/ISO-8859-6 encoding i did a test program to see if i will be able to see the characters in Unicod(eclips-debug) i read the file using Reader r = new BufferedReader(new InputStreamRead

  • Help! How to export for specific resolution?

    What is the best resolution to export photos for Facebook/Blog/High Res?

  • Install failure on Korean AIX

    An i2 customer is installing Weblogic Server 8.1SP1 on AIX 5.1 (Korean) the silent install has errors that start with the following warning: WARN [readCachedArchiveInfo] com.bea.plateng.wizard.installer.silent.tasks.ReadCachedArchiveInfoTask - Unable

  • Excise invoice craeteion error

    Hi all,, I am executing a factory sale in TAXINN procedure. when i am saving the  excise invocie in a J1IIn transaction getitng below error " Error in FI document create " I checked all config and looks good. Also i can see all excise duties are flow