Searching for End of line char in a string...and EOF in string.

Suppose I open up a file and read it right into a StringBuffer. Once I have that, how can i searching using StringBuffer.indexOf(whathereforEOL) for a end of line, i suspect its perhaps some sort of escape character but I am not sure what it is in java or if java even uses escape characters.
I really need
.indexOf(EOL); somehow, and perhaps .indexOf(EOF); //if end of file character is retrieved using a StringBuffer that was completed using a BufferedReader based on a input stream reader.
Thanks for any info here,
Shane

End-of-line is denoted in a platform-specific way.
Some variations depending on the platform:
"\r"
"\n"
"\r\n"
A sidenote. I remember some platforms maintaining the notion of "sequential" (and h�las, of "index-sequential") files. Unix and Windows store the files as byte streams without OS-imposed internal structure, that is the point of view of C as well.
But if you use BufferedReader.readLine() you get the lines one after the other.
EOF is handled by the OS. You will not read an "EOF" marker.
-1 rather denotes in the API that end-of-file is reached.
There is no way to actually read -1 as a byte or a character from a file or other data source.

Similar Messages

  • My group box is causing problems when searching for a text line in a text file.

    I am developing a booking system, so for this I need to ensure that no two clients can book the same appointment slot. So, on testing my code which prevents double booking, the system doesn't seem to find the text line being searched for in the text file
    when it (purposefully) should.
    I have tried isolating the problem using breakpoints, and I've found that when the 'SearchLine' (referring to my code below) does not include the 'TimeComboBox.text' piece and instead this value is written into the code, the system is able to find the SearchLine
    without any problems. But, when assigning the group box's value to a variable and using this in the SearchLine instead, or without even using a loop and just doing a simple line by line search, the program can't find this line of text in the file.
    I'm lost for ideas. I have tried everything I can think of. Could anyone make any suggestions as for what is the problem with my group box? (I'll explain the code beneath it).
    'Setting the value of the SearchLine (which is a String)
    SearchLine = String.Concat(DateTimePicker1.Value.Date & " " & TimeComboBox.text)
    Dim FoundApp As Boolean
    Dim objReader As New System.IO.StreamReader(basicfilepath & "Text Files\Client Booked Appointment DatesTimes.txt")
    FoundApp = False
    'Reading the file's contents and checking for the SearchLine
    Do While (objReader.Peek() <> -1) or (FoundApp = True)
    If (TextLine = SearchLine) Then
    'Line contains SearchLine. Appointment already exists.
    FoundApp = True
    Else
    'Line doesn't contain SearchLine. Carry on searching.
    Msgbox("Line not found.")
    End if
    Loop
    Explanation
    When the line is searched for, the 'FoundApp' value must be set to 'True' when it is found. If it is not found, it remains false.
    To isolate the problem, I've displayed the SearchLine in a message box in the past to make sure that the correct line of text is being searched for.
    In basic terms, my program is searching for the exact line of text which exists in the text file, but for some reason it is not coming up as 'Found'. The error occurs when the group box's value is used. The text file which is being read is
    definitely correct. Please help, any suggestions would be appreciated.
    Thank you

    Hi
    It would appear that your snippet doesn't actually read the file at all.
    Here is my test which works fine.
    Option Strict On
    Option Infer Off
    Option Explicit On
    Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
    Dim SearchLine As String = "18:09:38 : XTaskSettings.Load PARAMS: begin"
    Dim FoundApp As Boolean = False
    Dim TextLine As String = Nothing
    Dim objReader As New IO.StreamReader(Application.StartupPath & "\Data\Report Q1.txt")
    FoundApp = False
    Do While (objReader.Peek() <> -1) Or (FoundApp = True)
    ' this was missing
    TextLine = objReader.ReadLine
    If (TextLine = SearchLine) Then
    'Line contains SearchLine. Appointment already exists.
    FoundApp = True
    MsgBox("Line found.")
    Else
    'Line doesn't contain SearchLine. Carry on searching.
    MsgBox("Line not found.")
    End If
    Loop
    End Sub
    End Class
    Regards Les, Livingston, Scotland

  • Parallelized for loop. Searching for a one-line solution

    Hi.
    In an usual day I do a lot of for loops inside of command line. But I noted that my loops don't use the full power of my dual core processor, they only use one processor.
    A lot of the loops I do have independent interactions in the sense that a interaction code don't need the results of another interaction. This is the simplest problem in multiprocessing, I only need to execute N process in parallel.
    I'm searching for a one-line solution that I can use in place of a 'for i in *.txt; do echo $i;done'. With one-line I means that can be used as one-line but the implementation can be longer. And can be in any programming language.
    For now I'm using the following small python solution (the smallest I could get)
    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    from multiprocessing import Pool
    from glob import glob
    from subprocess import call
    def f(x):
    call(['asy', '-f', 'png', '-render=0', x])
    pool = Pool(processes=4)
    pool.map(f, glob('*.asy'))
    But I like something that can be integrated in my "shell life". Anyone know a solution for my problem?

    http://stackoverflow.com/questions/3816 … ash-script
    http://www.mail-archive.com/bug-bash@gn … 05820.html
    Last edited by karol (2009-11-23 00:30:34)

  • Search for a blank line

    how can i search for a blank line thru a java program??

    how can i search for a blank line thru a java
    program??You can use following code:
    BufferedReader reader = null;
    try{
    File file = new File("C:/temp/abc.txt");
    FileReader reader = new FileReader(file);
    BufferedReader reader = new BufferedReader(reader);
    String line = null;
    while( (line = reader.readLine()) != null ){
    if(line.trim().length() == 0){
    //Code for handling the blank line.
    } else {
    //Code for handling the line with content.
    } catch(IOExcepttion ioe) {
    ioe.printStackTrace();
    } finally{
    if(reader != null){
    try {
    reader.close();
    }catch(IOException io){
    System.out.println("Error occured while closing Reader");

  • 1) I pressed Menu\Bookmarks\ShowAllBookmarks to open bookmarks organizer. 2) I pressed Ctrl-F to search for some bookmark(s) (e.g. newspaper domain) and found some. NOW The qustion is "Which folder this/these bookmark(s) are actually located in"?

    Salut!
    The scenario is "Find bookmark existed before and recall which bookmarkfolder it is in"
    Please note the "folder" is for "bookmarks", NOT a file folder of HDD-filesystem
    1) I pressed Menu\Bookmarks\ShowAllBookmarks to open bookmarks organizer.
    2) I pressed Ctrl-F to search for some bookmark(s) (e.g. newspaper domain) and found some.
    NOW The qustion is "Which folder this/these bookmark(s) are actually located in"?

    Hey, guys. Thanks for responding. I really didn't know I was so clueless about this stuff.
    I really thought "urxvt" could be used as an alias or, what we called in Debian, an alternative, to the rxvt-unicode-256color command. I guess not? I'm still trying to set up "vi" to be Vim as well, and I'll read more of the Wiki to figure that stuff out with Arch.
    So in the tty interface I can start zsh again just fine. That's old news. I removed the TERM setting and placed the resource in my .Xresources that derhamster said. Thanks.
    I also replaced the line in my Openbox rc.xml and menu.xml for terminal opening commands (can I use $TERM for those?)
    Now when I start Xorg (with Openbox running) I tried both urxvt-unicode-256color and urxvt but none of them work with Openbox. No terminal emulator pops up and no errors show that I can see.
    Last edited by mrrhq (2012-11-13 18:34:29)

  • TS4611 I have just received my second MacBook Air 11" the Wifi connection keeps dropping. Also after 3 meters away it keeps searching for network! It is the second try and the same issue. Will Apple ever come up with a solution?

    I have just received my second MacBook Air 11" the Wifi connection keeps dropping. Also, after 3 meters away from the rooter it keeps searching for network! It is the second try and the same issues. Will Apple ever come up with a solution? There is a program pack for the connection issue but I cannot believe that this computer wifi keeps connected only while nearby the rooter!

    Applied this update?
    http://support.apple.com/kb/TS4611?viewlocale=en_US&locale=en_US
    If the update is installed aready, you may have to wait until OS X 10.8.5
    update if and when it is relased.
    Best.

  • Search for end-of-paragraph before end of story? CS6

    Hi,
    Does anybody know of a way to search for a paragraph mark directly
    before an end of story marker? I'd like to get rid of them, e.g., in
    footnotes, where the last paragraph mark causes an unnecessary blank line.
    Thanks,
    Ariel

    I found \z on Mike Witherell's great little chart at http://www.jetsetcom.net/useful-resources/indesign-cs6-resources.html
    End of paragraph, at least in GREP is a location, not a character (the metacharacter is $) and can't be selected or replaced. Every paragraph has one. Paragraphs before the end of story also have a paragaph break, and that's what you are trying to remove at the end of your footnote story.
    @David, Why bother withthe lookahead? \z is the location, so I would presume that the search would start at the end of story and look at the last character. That has to be faster than parsing every break in the paragraph to check for the end of story location after, and there's no possibility that you will actually delete the EOS since it can't actually be selected.

  • How to delete the ends of line ["\n"] in a String before parsing

    hi, i'd want to parse a String with Regex/Pattern.
    This String contains ends of line i want to delete before applying my parsing treatment.
    I've tried to do that by replacing the character "\n" with "" :
        // the original text
        String orgTextToParse = new String(buffer);
        //we create a pattern to recognize the ends of line
        String regExpEol = "\n";
        Pattern patternEol = Pattern.compile(regExpEol);
        Matcher matcherEol = patternEol.matcher(orgTextToParse);
        // the new text without end of line
        StringBuffer newTextToParse = new StringBuffer();
        // we replace the "\n" by ""
        while(matcherEol.find()) {
          String REPLACE = "";
          matcherEol.appendReplacement(newTextToParse,REPLACE);
        matcherEol.appendTail(newTextToParse);
        System.out.println("[new string start] " + (newTextToParse.toString()) + " [end of new string]");Is there an appropriate way to delete "\n" ?
    (perhaps a method of the Pattern or Matcher classes... ?)
    thanx
    Edited by: jfact on Dec 29, 2007 11:05 AM
    Edited by: jfact on Dec 29, 2007 11:06 AM

    The second (optional) argument to Pattern is a set of flags. Take a look at the Javadoc.
    The 'genomic' implication is that the EOL is an arbitrary line break for human consumption so it does look like you need to remove the EOL. I would just use replaceAll() since it can be done with one line of code (or just a couple if you pre-compile the regex) without the need for any looping.
    line = line.replaceAll("\n","");Edited by: sabre150 on Dec 29, 2007 10:27 AM

  • Searching for Apps to help us manage employee hours and all mobile plant maintenance and hours any suggestions

    We are currently looking for a way to get rid of paper in our business. We have machines all over the place as well as staff.
    Does anyone have a app that can manage employee hours and would be able to record plant (machine) hours and jobs?

    If you are using Quick books in your company you can search for apps through their system and there is one that integrates with QB15 that is great but i cant remember the name right this second .

  • How to search for a new line character in sql

    hi..i am using oracle 10g.
    basically i am looking for usage of columns.I want to see which all columns are used in
    joins.
    this is the quey i have written.
    but
    if there a new line between WHERE ,AND those scenarios are ignored.how to take care of these new line characters?
    SELECT DISTINCT s.TYPE, s.NAME, s.owner, table_name, column_name --,line,text
    FROM all_source s, cols c, all_dependencies d
    WHERE s.NAME = d.NAME
    AND d.referenced_name = c.table_name
    AND c.table_name = 'WSF_EDUCATION_ORGUNIT'
    AND column_name ='ORGUNIT_TYPECODE_OID'
    AND d.TYPE = s.TYPE
    AND d.TYPE <> 'PACKAGE'
    AND d.owner = s.owner ---FOR OVERLOADED OBJECTS
    AND ( (UPPER (text) LIKE
    '%' || 'AND' || '%' || column_name || ' ' || '=%'
    OR (UPPER (text) LIKE
    '%' || 'AND' || '%=' || ' ' || '%' || column_name
    || '%'
    UNION ---if there is where
    SELECT DISTINCT s.TYPE, s.NAME, s.owner, table_name,
    column_name ----,line,text
    FROM all_source s, cols c, all_dependencies d
    WHERE s.NAME = d.NAME
    AND d.referenced_name = c.table_name
    AND c.table_name = 'WSF_EDUCATION_ORGUNIT'
    AND column_name ='ORGUNIT_TYPECODE_OID'
    AND d.TYPE = s.TYPE
    AND d.TYPE <> 'PACKAGE'
    AND d.owner = s.owner ---FOR OVERLOADED OBJECTS
    AND ( (UPPER (text) LIKE
    '%' || 'WHERE' || '%' || column_name || ' ' || '=%'
    OR (UPPER (text) LIKE
    '%' || 'WHERE' || '%=' || ' ' || '%' || column_name
    || '%'
    )

    Hi,
    Not sure if I get it, but you can look for characters using the ascii and chr functions.
    You can change them using replace:
    A new line:
    SQL> select ascii('
      2  ') from dual;
    ASCII('')
            10(Just press enter between the quotes)
    Example how to replace it with a space:
    SQL> with t as ( -- generating test string:
      2  select 'this string has
      3  a new line' str from dual
      4  )
      5  --
      6  -- actual query:
      7  --
      8  select str
      9  ,      replace(str, chr(10), chr(32))
    10  from   t;
    STR                        REPLACE(STR,CHR(10),CHR(32
    this string has            this string has a new line
    a new lineIf that isn't clear of when I'm missing the point then please post some narrowes down examples of what you get now and your desired output. Remember to put the tag around any code example you're posting.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • How to search for a certain substring in a big string

    Hi gurus,
    Please help me with this requirement.
    We are waiting for 10.2.0.5.0 for a fix for an xml type cast error due to mixed encoding in the xml string :
    ORA-31011: XML parsing failed
    ORA-19202: Error occurred in XML processing
    LPX-00216: invalid character 0 (0x0)
    So for now, if I encounter the error, I want to extract the court file number (<CourtFileNumber>) from the xml string (CLOB type in PL/SQL) so that I know which file has failed. The xml string is like this (part of it):
    <soap:Body>
         <CaseNotification schemaVersion="4:2" messageProducedDateTime="2008-12-18T09:16:01-06:00" updateUserAccount="SomeUserName" xmlns="http://www.ourpartner.com/TheirXMLSchema/4>
              <NotificationAdminHeader caseNumberKey="77K903003304" caseKey="3336618">
                   <CourtFileNumber>
                        <ID>77-K9-03-003304</ID>
                   </CourtFileNumber>
              <CaseCountyNumber>77</CaseCountyNumber>
    Besides searching the string character by character, is there an easier way to look for the whole phrase "<CourtFileNumber>"?
    Thanks a lot.
    Ben

    SQL> set serveroutput on
    SQL> declare
      2      v_xml  clob;
      3      v_CourtFileNumber varchar2(100);
      4  begin
      5      v_xml := '<soap:Body>' ||
      6               '<CaseNotification schemaVersion="4:2" messageProducedDateTime="2008-12-18T09:16:01-06:00" updateUserAccount="SomeUserName" '||
      7               'xmlns="http://www.ourpartner.com/TheirXMLSchema/4>' ||
      8               '<NotificationAdminHeader caseNumberKey="77K903003304" caseKey="3336618">' ||
      9               '<CourtFileNumber>' ||
    10               '<ID>77-K9-03-003304</ID>' ||
    11               '</CourtFileNumber>' ||
    12               '<CaseCountyNumber>77</CaseCountyNumber>' ||
    13               '</soap>';
    14      v_CourtFileNumber := regexp_replace(v_xml,'.*<CourtFileNumber>(.*)<\/CourtFileNumber>.*','\1');
    15      if v_CourtFileNumber = v_xml then v_CourtFileNumber := null; end if;
    16      dbms_output.put_line('CourtFileNumber = ' || v_CourtFileNumber);
    17  end;
    18  /
    CourtFileNumber = <ID>77-K9-03-003304</ID>
    PL/SQL procedure successfully completed.
    SQL>
    {code}
    SY.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • How can I search for document content, specific words, in my scanned (and searchable) pdf files?

    When using spotloght to search my files for text within a scanned document, I may or may not find documents that were scanned by a scan program (ScanSnap) to a searchable PDF file on a firewire attached drive.
    Is there a specific manner that yeilds useable results 100% of the time?

    Spotlight should index PDF files (as well as Word and some other kinds of files) but it seems that PDFs are not created equal. I've seen and heard complaints that some scanner/OCR programs are saving files that aren't searchable and yours is one of them. Try opening one of the files in Preview and resaving it.

  • What is the process for transferring 2 lines from separate family plans and joining them in their own share plan?

    I am part of a family plan (not the owner) and my boyfriend is part of a family plan, also not the owner of it.  We would like to transfer both of our phones out of our family plans and do our own share plan together. What is the process for this??

    Have each of the account owners contact Verizon to let them know that you will be doing an AOL on your lines. Then you call Verizon and explain what you want to do. Just that easy. But understand you'll have to get the new Share everything plan.

  • How to search for a particular word in a given string?

    Ex: I want to search wether the following string contains "java" or not.
    "Java Technology Forums"
    Thanks....................

    The String API might be useful to you. In particular, the contains method.

  • Every time I launch Safari on my iPad there are about 5 or 6 tabs load ed with Wikipedia searches. I am the only one using the iPad so I know it's not me searching for this. Anyone else have this problem and if so how do I turn it off?! Thanks!

    Can anyone help? This is getting frustrating!

    Have you closed the tabs ? Re-opening Safari will open it with the same tabs that were open on it the last time that you used it.
    You can clear Safari's history via Settings > Safari > Clear History (and possibly Clear Cookies And Data), and then close Safari via the iPad's taskbar : from the home screen (i.e. not with Safari app 'open' on-screen) double-click the home button to bring up the taskbar, then press and hold any of the apps on the taskbar for a couple of seconds or so until they start shaking, then press the '-' in the top left of the Safari app to close it, and touch any part of the screen above the taskbar so as to stop the shaking and close the taskbar.
    When you re-open it there shouldn't be any open tabs.

Maybe you are looking for

  • Problem while doing invoice for Credit memo request

    Hi all I very well known that Out boud Delivery is not needed for Credit memo request but after saving the CMR and when i raise the Credit Memo (VF01) system is showing a error message saying "PGI not done for Outbound Delivery 30047402" In CMR docum

  • The words in iBooks are showing up jumbled, does anyone know why or how to fix it?

    I just had to restore my iPad 2 and when I went to read my books all of the words are not words, they are a jumbled mess. I tried deleting the books are reels loading them but it did not fix the problem. Any ideas?

  • How can I read content from PDF file stored in Oracle 9i XMLDB

    Hi Friends: Now I have met one question that I don`t know how to read some String , for example "Hello", from the PDF file stored in the Oracle 9i XMLDB, I have stored that PDF file into the XMLDB now, any suggestions are appriciated . Thank you in a

  • Subcontracting Handling ByProducts

    Hi I created a BOM with two components and there is one component as negative qty which is generated as By Product. When I am creating a subcontracting PO with Item Category "L" I am able to expolde the BOM with Two Components only and the negative q

  • PI vs CE - ESR

    Hi All, We currently have PI 7.1. There is a ESR that came with PI 7.1(previously called Intergration Repository in PI 7.0). I am confused as to why i would need a CE 7.1 system and another ESR on CE? What purpose would a CE system server if PI 7.1 i